Parallel Programming with .NET

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I came up with what I think is a good idea for making multithreading
programming easier in any .NET language. I dont know where else to post it,
so I'll try here.

..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.
e.g. (theoretical c#)


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 multithreaded code. I've
actually added this feature to a compiler I'm working on and it works quite
nicely.
 
Not quite what you asked for but, if you go to
http://research.microsoft.com/research/downloads/default.aspx and download
the bits for
"C# Software Transactional Memory" you will find some help for creating
parallel threaded systems.

MSR is very cool.
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
<=?Utf-8?B?Sm9zaHVhIE51c3NiYXVt?= <Joshua
(e-mail address removed)>> wrote:

I think this would make it much easier to write multithreaded code. I've
actually added this feature to a compiler I'm working on and it works quite
nicely.

I don't know - I can't think of many situations where I've used
multithreading where it would be more readable than doing things more
explicitly.

I prefer the language to remain nice and small, not having much stuff
which is threading-specific. (Even "lock" would have been better to use
the "using" pattern, IMO.)
 
Jon Skeet said:
<=?Utf-8?B?Sm9zaHVhIE51c3NiYXVt?= <Joshua
(e-mail address removed)>> wrote:



I don't know - I can't think of many situations where I've used
multithreading where it would be more readable than doing things more
explicitly.

I prefer the language to remain nice and small, not having much stuff
which is threading-specific. (Even "lock" would have been better to use
the "using" pattern, IMO.)

While I tend to agree, I do see some value in allowing easy parallelization
of loops or over enumerations. However it certainly can be converted to an
API.
 
Joshua Nussbaum said:
I came up with what I think is a good idea for making multithreading
programming easier in any .NET language. I dont know where else to post
it,
so I'll try here.

.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.
e.g. (theoretical c#)
<snip examples>

What I have to ask is why would a compiler option be best here? Could you
not use 2.0 anonymous method and a simple api:

Parallel.NonBlockingExecute(
delegate { //do IO },
delegate {//do DB },
delegate {//do network },
)

or
Parallel.BlockingExecute(
delegate { //do IO },
delegate {//do DB },
delegate {//do network },
)

// thread blocks until all parallel anonymous functions complete
Console.WriteLine("Tasks complete");


I do see value in parallelization in the language(or a subset of it anyhow),
but not in this particular form. Permitting the runtime or language to
parallelize long running loops in a form that OpenMP permits would be
interesting, for example.

On other news, Its nice to see someone else working on a compiler. Are you
starting from scratch or basing off mono's?
 
Thanks, that was helpful.

I actually started my compiler from scratch. its basically an XML syntax
for writing .NET programs. e.g.

<method name="Foo">
<parameters>
<parameter type="int" name="arg1"/>
</parameters>
<statements>
<if condition="arg1 == 22">
<statements>
<declare type="SomeClass" variable="obj" initializer="NEW SomeClass()"/>
<call expression="obj.CallMe()"/>
</statements>
</if>
</statements>
</method>

Because i'm using XML and I have an XML schema, half of the code validation
is done out of the box. So I beleive the mono compiler is overkill for this
project. (though my compiler should be able to run on the mono clr)

The idea isnt to hand code applications in XML, that would be very tedious.
So I'm also working on an IDE for writing code completely visually.

Avalon and 3D interfaces are coming, and I think it can help IDE technology
too.
 
Josh Nussbaum said:
Thanks, that was helpful.

I actually started my compiler from scratch. its basically an XML syntax
for writing .NET programs. e.g.

<method name="Foo">
<parameters>
<parameter type="int" name="arg1"/>
</parameters>
<statements>
<if condition="arg1 == 22">
<statements>
<declare type="SomeClass" variable="obj" initializer="NEW SomeClass()"/>
<call expression="obj.CallMe()"/>
</statements>
</if>
</statements>
</method>

Because i'm using XML and I have an XML schema, half of the code
validation
is done out of the box. So I beleive the mono compiler is overkill for
this
project. (though my compiler should be able to run on the mono clr)

Ahh, I see. I thought you meant a C# compiler, ;).

Interesting idea, good luck on it.
 
Back
Top