Main Site Documentation

The problem with multithreaded applications, is threads


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?


C# ?


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



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.


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


What does IoT have to do with multicore MCUs?


@ godefroi - multicore uControllers do exist already in fact.

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


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


[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.


I also would suggest C# (I guess any .NET language should work).
Specially if you look at the System.Threading.Tasks namespace.
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) {
                                                      if (! Char.IsWhiteSpace(uCh)) {
                                                         lock (obj) {
                                                   } );
      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


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


@ 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:


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.


@ godefroi - true, true.


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


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)