Main Site Documentation

The problem with multithreaded applications, is threads


#1

I believe that the problem with multithreaded applications is threads. I believe that the programming language has to have features for multithreading as opposed to it being a framework or toolkit.

With that said, apart from F# does anyone use a programming language that is good at multithreaded operations? My workstation has 24 threads (dual hex core xeon with HT) and I’m constantly needing to consider multi threading.

I also ask for the future of .netmf. One day there will be multicore micro controllers; what then?


#2

C# ?


#3

@ Mr. John Smith - good place to start to take advantage of those 24 threads :wink:

http://msdn.microsoft.com/en-us/library/dd460693(v=vs.110).aspx


#4

#5

I’m not holding my breath for multicore microcontrollers. Even if there were such a thing (for some definition of microcontroller), I personally would stay away, if only for cost, size, and power consumption reasons.

Remember, the 8048 and 8051 are still around, for exactly those reasons. I wouldn’t be surprised to learn that most microcontrollers shipped even today are 8-bit devices.


#6

@ godefroi - Its based on a prediction that IoT will become popular one day.


#7

What does IoT have to do with multicore MCUs?


#8

@ godefroi - multicore uControllers do exist already in fact.
http://www.nxp.com/products/microcontrollers/cortex_m4/lpc4300/

Low power consumption is of the reasons you might pick one.

http://www.ganssle.com/tem/tem228.html#article2


#9

Not really multi-core in the sense @ Mr. John Smith meant, though.


#10

[quote=“Mr. John Smith”]
I believe that the problem with multithreaded applications is threads[/quote]

I believe the problem with multithreaded applications is they’re multithreaded. As soon as you toss in multithreading you are now open to the randomness and complexities of time and sequence among other things.

C# has pretty good multithreading features, but no matter how easy you make it to include multithreading in the language, the issues and complexities around threading are a given.

The first time I had to really wrap my head around threading, was on a BBN Butterfly Computer, think pretty much free for all threading with the accompanying consequences.


#11

I also would suggest C# (I guess any .NET language should work).
Specially if you look at the System.Threading.Tasks namespace.
http://msdn.microsoft.com/en-us/library/system.threading.tasks(v=vs.110).aspx
You can find a lot of very nice stuff like:

using System;
using System.IO;
using System.Threading.Tasks;

public class Example
{
   public static void Main()
   {
      Task<String> task = ReadCharacters(@ ".\CallOfTheWild.txt");
      String text = task.Result;

      int nVowels = 0;
      int nNonWhiteSpace = 0;
      Object obj = new Object();

      ParallelLoopResult result = Parallel.ForEach(text, 
                                                   (ch) => {
                                                      Char uCh = Char.ToUpper(ch);
                                                      if ("AEIOUY".IndexOf(uCh) >= 0) {
                                                         lock (obj) {
                                                            nVowels++;
                                                         }
                                                      }
                                                      if (! Char.IsWhiteSpace(uCh)) {
                                                         lock (obj) {
                                                            nNonWhiteSpace++;
                                                         }   
                                                      }
                                                   } );
      Console.WriteLine("Total characters:      {0,10:N0}", text.Length);
      Console.WriteLine("Total vowels:          {0,10:N0}", nVowels);
      Console.WriteLine("Total non-whitespace:  {0,10:N0}", nNonWhiteSpace);
   }

   private static async Task<String> ReadCharacters(String fn)
   {
      String text;
      using (StreamReader sr = new StreamReader(fn)) {
         text = await sr.ReadToEndAsync();
      }
      return text;
   }
}
// The example displays output like the following: 
//       Total characters:         198,548 
//       Total vowels:              58,421 
//       Total non-whitespace:     159,461

Taken from the MSDN documentation


#12

Languages with strong support for immutable types can make multithreading easier. See F#.


#13

@ Duke Nukem - Nah, I’m not looking for features; where the language can do as opposed was built to do. Take the difference between C++ and Java. C++ is functional programming with objects while Java is object oriented programming. F# seems to have been build with multithreading in mind, and it is a declarative programming language. I’ve used C# with parallel for (and without parallel for). To most developers multithreading just means starting a thread to perform some complex task, as opposed to creating that task so that it works with N number of processors. Hand an average developer a super computer with 512 cpus and 2096 cores and they will write the app to utilize only 4 threads.

I guess what I’m asking is what languages/techniques do they use to develop applications for supercomputers :open_mouth:


#14

F# is primarily a functional language, though it does have imperative features as well. Functional languages are generally (at least theoretically) good with lots of threads, where imperative languages aren’t as good.


#15

@ godefroi - true, true.


#16

Fortran - flat memory model fast, stack based memory model slow.


#17

According to the latest news from Microsoft, Windows 10 should run on super computers like a charm. That means you can write an universal app for it 8)