[libdispatch-dev] Possible race in _dispatch_logv when DISPATCH_DEBUG is defined?

Daniel A. Steffen dsteffen at apple.com
Mon Jul 4 19:29:13 PDT 2011


I wouldn't worry about it, once the merge with the Lion changes is done, this initialization will be implemented with dispatch_once_f() (still working on it...)

On Jul 4, 2011, at 6:46 PM, DrPizza wrote:

> The intended pattern in _dispatch_logv is to have a static FILE* logfile for the log file, lazily initialized by the first thread to call the function. To avoid locking, every thread that sees that logfile is empty opens the log file in a private per-thread FILE*, and then tries to cmpxchg that into the static value. Any thread that loses the race just closes its private copy and uses the shared one.
> 
> However, tmp has been marked static too, which means that if several threads are executing _dispatch_logv simultaneously, they'll clobber each other's tmp. That seems of dubious value to me; I think tmp should be non-static.
> 
> Peter
> 
> _______________________________________________
> libdispatch-dev mailing list
> libdispatch-dev at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/libdispatch-dev



More information about the libdispatch-dev mailing list