On Thu, Dec 24, 2009 at 5:17 AM, Nicolas Cannasse
Post by Owen DurniBesides the differences in API, is there any difference between a
[neko|cpp].vm.Lock and a [neko|cpp].vm.Mutex?
A lock is much more feature-complete, and can be released by an different
thread than the one which acquired it.
I assume this is not the case with a Mutex then (this should probably
be mentioned in the API).
You can also do several release() and
as much wait() if you want for example limit a resource to a given number of
users.
But Lock is slower than Mutex, especially on Windows.
So it sounds like one should use a Mutex unless the additional
features of a Lock are required.
Hi Owen,
A lock allows you to wait until all the locks have been released.
A mutex will let you lock, check a variable, and unlock, but you
will need to do this in a loop, which wastes CPU.
This is inconsistent with the docs for Mutex: "The calling thread
locks the mutex. If another thread has already locked the mutex, the
calling thread will block until it is released." (unless Mutex
"blocks" by spinning, in which case the docs should say so)
In any case, I just decided to experiment with synchronous message
passing in haXe. Probably won't have a chance to test this until after
the holidays, but my first step was to take the basic locks provided
and create a barrier:
http://www.evaryu.com/hg/concurrent/file/tip/src/concurrent/primatives/Barrier.hx
I haven't even had time to run the code yet, so I'm sure it has bugs still :)
Owen
--
haXe - an open source web programming language
http://haxe.org