[PATCH] pthread_fork Part 3

Robert Collins rbcollins@cygwin.com
Fri Sep 20 06:14:00 GMT 2002

On Fri, 2002-09-20 at 23:06, Thomas Pfaff wrote:

> If you want to work around this you must use a mutex to protect the entire
> list.

Or: don't delete foo; the keys, instead foo->deleteme();

  inuse_count = 1;

pthread_key::deleteme() {
  if interlockeddecrement (inuse_count) == 0
    delete this;

pthread_key::rundestructor() {
if (interlockeddecrement(inuse_count) == 0)
  delete this

This prevents the race you describe with no locks.

Still, this race is actually one ieee says we don't care about IIRC,
it's up to the user to synchronise calls like this.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20020920/75ba3eb0/attachment.sig>

More information about the Cygwin-patches mailing list