basic concurrency

John Demme me at teqdruid.com
Tue Apr 18 07:30:19 PDT 2006


Tydr Schnubbis wrote:

> If I have an array and want to synchronize all access to it (only one
> thread using it at a time), what's the best way?  I know how to use
> 'synchronized' to make a critical section, but I want to synchronize
> data, not code.

In Mango, Doug Lea's Concurrency library has been ported from Java.  It's
got locks and such.  You can create a ReadWriteLock to go along with that
data object and everything that wants to use the object can get a lock
before it does so.

Alternatively, I already have a ThreadSafeList wrapper class (which uses a
ReentrentReadWriteLock) which can be used with an ArrayList.  Both of these
are in mango.containers, which is only in SVN since it't still beta
quality- but the List branch of it tends to work pretty well.

~John Demme



More information about the Digitalmars-d-learn mailing list