www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D and parallel programming

reply John Burak <icrashedtheinternet gmail.com> writes:
I am looking into D as a possibility for a programming project I want to start.
 Can someone point me to resources on how D supports parallel programming,
assuming it does?  I'm surprised I didn't notice anything about parallel
programming on the "d language overview" page when I scanned/searched it. 
Unless it is there and I missed it (quite possible) then I think it should be
added so people know what D is capable of (I'm still assuming it has some
native support for parallel programming).

-John
Aug 06 2007
next sibling parent reply Sean Kelly <sean f4.ca> writes:
John Burak wrote:
 I am looking into D as a possibility for a programming project I want to
start.  Can someone point me to resources on how D supports parallel
programming, assuming it does?  I'm surprised I didn't notice anything about
parallel programming on the "d language overview" page when I scanned/searched
it.  Unless it is there and I missed it (quite possible) then I think it should
be added so people know what D is capable of (I'm still assuming it has some
native support for parallel programming).
Support for multithreaded programming (what I assume you meant by "parallel programming") in D largely amounts to a standard Thread object in the library, as well as a "synchronized" keyword which behaves quite similar to the one in Java. There is also a "volatile" keyword, but it is really only intended for lock-free programming and thus doesn't see much use outside of library code. If it helps, Tango also contains a Fiber implementation, a read-write mutex, condition variables, and semaphores. There is also a coroutine implementation and a CSP implementation at http://www.assertfalse.com. I think we still have a ways to go for easily usable concurrency in D, but the basic building blocks are there. Sean
Aug 06 2007
parent reply Regan Heath <regan netmail.co.nz> writes:
Sean Kelly wrote:
 Support for multithreaded programming (what I assume you meant by 
 "parallel programming") in D largely amounts to a standard Thread object 
 in the library, as well as a "synchronized" keyword which behaves quite 
 similar to the one in Java.  
Except that (importantly, IMO) it's re-entrant. By that I mean, if you have: class Foo { int i; void bar() { synchronized(this) { i++; } } } void main() { Foo f = new Foo(); synchronized(f) { f.bar(); } } you get no deadlock. As I believe they do in Java (someone correct me if I'm wrong). In short, multiple synchronized blocks, on the same object, in the same thread are allowed and do not cause a deadlock. Regan
Aug 07 2007
parent =?ISO-8859-1?Q?Julio_C=E9sar_Carrascal_Urquijo?= writes:
Regan Heath wrote:

using System; class Foo { int i; public void bar() { lock (this) { i++; } } public static void Main() { Foo f = new Foo(); lock (f) { f.bar(); } } } It works but it is always recommended to lock on a private object because there are some corner cases where it will dead-lock. Something like the following is always preferred: readonly object syncRoot = new object(); (...) lock (syncRoot) { (...) }
Aug 07 2007
prev sibling parent Robert Fraser <fraserofthenight gmail.com> writes:
John Burak Wrote:

 I am looking into D as a possibility for a programming project I want to
start.  Can someone point me to resources on how D supports parallel
programming, assuming it does?  I'm surprised I didn't notice anything about
parallel programming on the "d language overview" page when I scanned/searched
it.  Unless it is there and I missed it (quite possible) then I think it should
be added so people know what D is capable of (I'm still assuming it has some
native support for parallel programming).
 
 -John
It has a synchronized keyword and threads in both standard libraries (Tango's threading support is a bit more robust, as it has futures and fibers)...
Aug 06 2007