Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2001-08-13 03:01:06


> In my opinion, thread specific data functions
> are in Posix because of the faulty Unix/C model.
> They exist because programmers are ignorant of good design,
> and don't understand that implicitly coupled global data --
> including thread specific data -- is bad design.
> In particular, if you're trying to upgrade such bad designs
> to support threads, then the Posix functions are there
> to minimise the effort required.

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

init {

  tsd::init( &key );
  lock::init( &lock );
  nCount = 0;

}

destroy {

  lock::destroy( &lock );
  tsd::destroy( &key );

}

lock {

  if ( 0 == tsd::get( &key ) ) {

    tsd::set( &key,&key ); // ownership pending..

    lock.acquire();

    nCount = 1;

  }
  else {

    ++nCount;

  }

}

unlock {

  if ( 0 == --nCount ) {

    lock.release();

    tsd::set( &key,0 ); // retract ownership status

  }

}

regards,
alexander.


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