druntime thread_needLock()

Fawzi Mohamed fmohamed at mac.com
Sat Dec 6 14:49:34 PST 2008


On 2008-12-06 17:13:34 +0100, Sean Kelly <sean at invisibleduck.org> said:

> Fawzi Mohamed wrote:
>> 
>> a memory barrier would be needed, and atomic decrements, but I see that 
>> it is not portable...
> 
> It would also somewhat defeat the purpose of thread_needLock, since IMO 
> this routine should be fast.  If memory barriers are involved then it 
> may as well simply use a mutex itself, and this is exactly what it's 
> intended to avoid.

the memory barrier would be needed in the code that decrements the 
number of active threads, so that you are sure that no pending writes 
are still there, (that is the problem that you said brought you to 
switch to a multithreaded flag), not in the code of thread_needLock...

But again I would say that this optimization is not really worth it (as 
you also said it), even if it is relevant for GUI applications.

Fawzi




More information about the Digitalmars-d mailing list