[llvm-commits] [PATCH] Thread-safe ManagedStatic

Owen Anderson resistor at mac.com
Tue May 19 04:29:05 PDT 2009


On May 19, 2009, at 4:26 AM, Owen Anderson wrote:
>> 3. Why do you create your own mutex out of atomic operations instead
>> of just using a pthreads lock?  spinning is not always an efficient
>> solution to contention, particularly if your machine really only has
>> one cpu! (in which case you end up spinning away the rest of your
>> timeslice)
>
> Portability.  llvm::sys::Mutex _cannot_ be made to work, because on  
> Windows
> it has to have a non-trivial constructor.

To build on my own comment, this is also the reason behind having one  
lock per
object.  Since we have to write our own mutex implementation for this  
to work on Windows,
we are free to write one that uses zero as the unlocked state, and can  
thus be put within
each ManagedStatic, reducing lock contention.

Basically, given that we need to implement our own mutex, making one- 
per-object
seems like the natural next step.

--Owen
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2620 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20090519/3998a26d/attachment.bin>


More information about the llvm-commits mailing list