Re: Mutexes and locking

2014-03-06 Thread Kagamin
We use non-recursive locks too. The pattern is: --- bool wasMyLock=obj.isMyLock(); if(!wasMyLock)obj.lock(); ...code... if(!wasMyLock)obj.unlock(); ---

Re: Mutexes and locking

2014-03-05 Thread Ali Çehreli
On 03/05/2014 09:49 AM, Jeremy DeHaan wrote: > On Monday, 3 March 2014 at 07:38:05 UTC, Ali Çehreli wrote: >> The documentation says that Mutex is a recursive lock, meaning that >> the holder of the lock can lock it even further. :) There is an >> internal reference count so that the lock must be

Re: Mutexes and locking

2014-03-05 Thread Jeremy DeHaan
On Monday, 3 March 2014 at 07:38:05 UTC, Ali Çehreli wrote: The documentation says that Mutex is a recursive lock, meaning that the holder of the lock can lock it even further. :) There is an internal reference count so that the lock must be unlocked the equal number of times that it has been l

Re: Mutexes and locking

2014-03-04 Thread Sean Kelly
For what it's worth, you can also do: auto m = new Mutex; sycnchronized (m) { // do stuff } The synchronized block will call lock on enter and unlock on exit, even as a result of a throw.

Re: Mutexes and locking

2014-03-03 Thread yazd
On Monday, 3 March 2014 at 08:18:04 UTC, alexhairyman wrote: On Monday, 3 March 2014 at 07:38:05 UTC, Ali Çehreli wrote: On 03/02/2014 10:38 PM, alexhairyman wrote: > I think I'm missing something big, but I'm having troubles with mutexes > (using in a parallel foreach loop somewhere else); Why

Re: Mutexes and locking

2014-03-03 Thread alexhairyman
On Monday, 3 March 2014 at 07:38:05 UTC, Ali Çehreli wrote: On 03/02/2014 10:38 PM, alexhairyman wrote: > I think I'm missing something big, but I'm having troubles with mutexes > (using in a parallel foreach loop somewhere else); Why do the trylocks > return true shouldn't they return false bec

Re: Mutexes and locking

2014-03-02 Thread Ali Çehreli
On 03/02/2014 10:38 PM, alexhairyman wrote: > I think I'm missing something big, but I'm having troubles with mutexes > (using in a parallel foreach loop somewhere else); Why do the trylocks > return true shouldn't they return false because the mutex is already > locked? The documentation says t

Mutexes and locking

2014-03-02 Thread alexhairyman
I think I'm missing something big, but I'm having troubles with mutexes (using in a parallel foreach loop somewhere else); Why do the trylocks return true shouldn't they return false because the mutex is already locked? I don't think this is a phobos bug, I'm on OSX using dmd 2.065 import cor