Parrallism in .NET
-
I came up with what I think :) is a good idea for making multithreading programming easier in any .NET language. .NET 2.0 adds the capability to write anonymous functions, it would be nice if there was a "parallel" statement, that could simplify writing threadprocs
public void DoSomeParallelStuff() { parallel { { // do some network stuff // this is an anonymous ThreadProc } { // do some IO stuff } { // do some DB stuff } } // do other stuff, on caller thread }
behind the scenes the compiler could create the anonymous functions, add them to the ThreadPool by calling ThreadPool.QueueUserWorkItem. in some cases it would be nice to automatically block the caller thread, maybe a sister statement "parallel-blocked"parrallel-blocked { { // read from drive c: StreamReader rd = new StreamReader("C:\test.txt"); ... } { // read from drive d: (done in parallel) StreamReader rd = new StreamReader("D:\test.txt"); ... } } // thread blocks until all parallel anonymous functions complete Console.WriteLine("Tasks complete");
I think this would make it much easier to write multithread capable code. I've actually added this feature to a compiler I'm working on and it works quite nicely. 60% of statistics are made up on the spot -
I came up with what I think :) is a good idea for making multithreading programming easier in any .NET language. .NET 2.0 adds the capability to write anonymous functions, it would be nice if there was a "parallel" statement, that could simplify writing threadprocs
public void DoSomeParallelStuff() { parallel { { // do some network stuff // this is an anonymous ThreadProc } { // do some IO stuff } { // do some DB stuff } } // do other stuff, on caller thread }
behind the scenes the compiler could create the anonymous functions, add them to the ThreadPool by calling ThreadPool.QueueUserWorkItem. in some cases it would be nice to automatically block the caller thread, maybe a sister statement "parallel-blocked"parrallel-blocked { { // read from drive c: StreamReader rd = new StreamReader("C:\test.txt"); ... } { // read from drive d: (done in parallel) StreamReader rd = new StreamReader("D:\test.txt"); ... } } // thread blocks until all parallel anonymous functions complete Console.WriteLine("Tasks complete");
I think this would make it much easier to write multithread capable code. I've actually added this feature to a compiler I'm working on and it works quite nicely. 60% of statistics are made up on the spotThat would definitely be drool-worthy. Send a proposal to Microsoft and maybe it will see fruitation! :)