Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2001-08-15 05:16:45


> From: John Max Skaller <skaller_at_m...>
>
> Alexander Terekhov wrote:
>
> > could you please explain what is wrong with the following
> > design of e.g. win32-like recursive mutex using TSD/TLS
> > (usefulness/correctness of recursive locking aside):
> >
> given:
> >
> > key - tsd key (or sub-key)
> > lock - mutex/bin.semaphore (non-recursive lock)
> > nCount - int
>
> I presume 'tsd' means 'thread shared data'.
> In which case, I claim first a better design is to
> _pass_ each thread a pointer to the shared object.
>
> > init {
> >
> > tsd::init( &key );
>
> This call is clearly not typesafe:
> again, I presume it takes a void *. argument.
> If you pass to the thread a pointer to a
> data structure such as
>
> struct shared {
> int key;
> };
>
> or whaetever, then you can initialise the key
> in a typesafe manner. Furthermore, by sharing
> objects between _groups_ of threads, you can
> control which groups share with each other,
> and which are indepedent. That is, the design
> is both unsafe and inflexible, whereas passing
> a pointer to each thread explicitly is typesafe
> and flexible.
>
> But perhaps I misunderstood, so please explain
> if that is so (quite possible!)

'tsd' means 'thread specific data' also known as
'tls' ('thread local storage') or 'thread locals'.

http://www.opengroup.org/onlinepubs/007908799/xsh/pthread_key_create.html
http://www.opengroup.org/onlinepubs/007908799/xsh/pthread_setspecific.html
http://www.opengroup.org/onlinepubs/007908799/xsh/pthread_key_delete.html
http://java.sun.com/j2se/1.3/docs/api/java/lang/ThreadLocal.html
http://java.sun.com/j2se/1.3.0/docs/api/java/lang/InheritableThreadLocal.html
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/hh/winbase/prothred_25r9.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/hh/winbase/prothred_9ixx.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_core_thread_local_storage_.28.tls.29.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_core_rules_and_limitations_for_tls.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang98/HTML/_clang_thread_local_storage.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/aralpha98/Html/tls_example.asp

regards,
alexander.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk