|
Boost : |
From: John Max Skaller (skaller_at_[hidden])
Date: 2001-08-14 16:42:06
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!)
-- John (Max) Skaller, mailto:skaller_at_[hidden] 10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850 New generation programming language Felix http://felix.sourceforge.net Literate Programming tool Interscript http://Interscript.sourceforge.net
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk