By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,122 Members | 2,029 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,122 IT Pros & Developers. It's quick & easy.

Parallel Programming with .NET

P: n/a
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.

Jul 21 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Add the 'YouKnowWhatIMean' and 'HereAMiracleOccurs' while your'e at it.
"Joshua Nussbaum" <Joshua Nu******@discussions.microsoft.com> wrote in
message news:2B**********************************@microsof t.com...
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.

Jul 21 '05 #2

P: n/a
Not quite what you asked for but, if you go to
http://research.microsoft.com/resear...s/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.
--
"Joshua Nussbaum" <Joshua Nu******@discussions.microsoft.com> wrote in
message news:2B**********************************@microsof t.com...
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.

Jul 21 '05 #3

P: n/a
<=?Utf-8?B?Sm9zaHVhIE51c3NiYXVt?= <Joshua
Nu******@discussions.microsoft.com>> wrote:

<snip>
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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #4

P: n/a

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<=?Utf-8?B?Sm9zaHVhIE51c3NiYXVt?= <Joshua
Nu******@discussions.microsoft.com>> wrote:

<snip>
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.)


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.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #5

P: n/a

"Joshua Nussbaum" <Joshua Nu******@discussions.microsoft.com> wrote in
message news:2B**********************************@microsof t.com...
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?
Jul 21 '05 #6

P: n/a

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<=?Utf-8?B?Sm9zaHVhIE51c3NiYXVt?= <Joshua
Nu******@discussions.microsoft.com>> wrote:

<snip>
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.)


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.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #7

P: n/a

"Joshua Nussbaum" <Joshua Nu******@discussions.microsoft.com> wrote in
message news:2B**********************************@microsof t.com...
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?
Jul 21 '05 #8

P: n/a
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.

"Daniel O'Connell [C# MVP]" wrote:

"Joshua Nussbaum" <Joshua Nu******@discussions.microsoft.com> wrote in
message news:2B**********************************@microsof t.com...
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?

Jul 21 '05 #9

P: n/a
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.

"Daniel O'Connell [C# MVP]" wrote:

"Joshua Nussbaum" <Joshua Nu******@discussions.microsoft.com> wrote in
message news:2B**********************************@microsof t.com...
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?

Jul 21 '05 #10

P: n/a

"Josh Nussbaum" <Josh Nu******@discussions.microsoft.com> wrote in message
news:CA**********************************@microsof t.com...
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.

Jul 21 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.