[PATCH] pthread_fork Part 3

Thomas Pfaff tpfaff@gmx.net
Fri Sep 20 06:06:00 GMT 2002



On Fri, 20 Sep 2002, Robert Collins wrote:

> On Sat, 2002-08-17 at 06:55, Thomas Pfaff wrote:
> >
> > Pthread key destructor handling revised. IMHO it does not make sense to
> > handle two lists with keys, one with all keys, one with its destructors.
> > The destructors are now part of the key class.
>
> I agree with the duplication of code. This is one area I'd really really
> really like to use templates.
>
> Chris, Corinna, if we ever get the chance to use templates please tell
> me so! It makes code clarity and size so much better.
>
> Anyway, yes, we should only have one list. So yes, please do refactor
> the two together in the way I've arranged the pthread_keys::keys list.
>
> Note that you have a comment on non thread safeness in the new
> pthread_keys code. I thought I had addressed that in my list code, could
> you either tell me I was also not thread safe, or correct that at the
> same time?

While the list has thread safe inserts and deletes via Interlocked
functions it can be theoretically possible that a thread deletes a key
while another run the destructor function of exactly this key which will
lead to an segfault. IMHO the possibility that this will ever happen is 0,
because keys are normally created at program start and deleted at the end
and not dynamically created and destroyd.

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

Thomas



More information about the Cygwin-patches mailing list