[Spread-users] Question about thread-safety

John Schultz jschultz at d-fusion.net
Tue Jun 17 17:52:29 EDT 2003

Theo E. Schlossnagle wrote:

> If you hand back a context pointer (still opaque), you solve all that.  
> You don't let the user see inside the context at all (it is effectively 
> an "externally unique" integer handle).  This is how many other library 
> interfaces work.  Then, the full contect implementation (inside the 
> library) can have whatever synchronization crutches it need stored 
> inside the context.

Your method would still require that the user ensure that all threads 
that might use the context, stop using the context before it is reclaimed.

This is common practice for libraries but with almost no additional work 
(a lookup per call) the table method takes that synchronization problem 
off of the user's hands.  The user can reclaim/close the handle at any 
time in any thread and any threads that subsequently try to use that 
handle will get an INVALID_HANDLE error and can assume that some other 
thread already closed/reclaimed the handle.

Finally, we can guarantee in practice (use a big counter and exit if we 
flip it) that our integer handles are "eternally unique" whereas malloc 
_might_ return the same pointer twice.

John Schultz
Co-Founder, Lead Engineer
D-Fusion, Inc. (http://www.d-fusion.net)
Phn: 443-838-2200 Fax: 707-885-1055

More information about the Spread-users mailing list