From: Daniel A. S. <st...@ic...> - 2005-04-28 06:01:04
|
Zoran, thanks for having a look at this On 28/04/2005, at 4:23, Zoran Vasiljevic wrote: > Why do you bother using spin locks for synchronization? as mentioned, I followed Apple's opensource CFSocket implementation, which uses this style of locking on Darwin: http://darwinsource.opendarwin.org/10.3/CF-299/RunLoop.subproj/ CFSocket.c for locking APIs, c.f. http://darwinsource.opendarwin.org/10.3/CF-299/Base.subproj/ CFInternal.h > Why not just using simple pthread_mutex (i.e. Tcl_Mutex)? we cannot use Tcl_Mutex because this code needs to work in an unthreaded core as well, but we could use pthread_mutex directly. the reason I used the libSystem spinlock API is that it is much simpler to setup (i.e. no setup) and has lower overhead. Also, in a first go at the problem, I didn't want to replicate all the Tcl_Mutex machinery in tclMacOSXNotify.c but we can of course do so if it really has advantages. > Spinlocks are rarely a good idea exept when sitting in > the kernel and/or locking very tight. > I doubt that it will make any difference. It may even > turn out to be slower... AFAIU the libSystem spinlock API immediately yields on a single processor, and spins very briefly on a multiprocessor and then yields. Certainly all of CoreFoundation uses spinlocks for locking... Cheers, Daniel -- ** Daniel A. Steffen ** "And now for something completely ** Dept. of Mathematics ** different" Monty Python ** Macquarie University ** <mailto:st...@ma...> ** NSW 2109 Australia ** <http://www.maths.mq.edu.au/~steffen/> |