[c++-pthreads] concrete library-code example
Jason Merrill
jason at redhat.com
Thu Dec 25 18:23:13 UTC 2003
On Wed, 24 Dec 2003 22:42:19 -0800, Nathan Myers <ncm at cantrip.org> wrote:
> On Wed, Dec 24, 2003 at 11:55:59PM -0500, Jason Merrill wrote:
>> This is not cancellation-safe C under the current POSIX standard, if
>> c_function_or_system_call is a cancellation point. If it is, cleanups
>> are run and the thread is terminated. To be truly thread-safe, the
>> user must use pthread_cleanup_push/pop so that the resources are
>> released on cancellation.
>
> I think that is what I said. It was thread-safe code until the
> semantics of calls it uses changed without changing the names.
> What was good code is now broken, in a POSIX C thread-cancellation
> environment.
In what sense was it ever thread-safe? It was fine for non-threaded code,
but has always been broken in a POSIX threads environment.
>> Implementing cancellation by throwing an exception has no effect on
>> the thread-safety of this code.
>
> In other words, because (under the C binding) this code has already
> been broken, throwing exceptions through it won't break it any further.
Yes.
> However, we're not talking about the C binding here. This list is for
> discussion of a C++ binding, which need not be so procrustean as the
> C binding.
Currently, the C++ binding is the C binding, so your example is broken
under C++ as well. And it would seem rather odd for the C++ binding to go
to great lengths to accommodate code which is broken under C, when C++
already provides a simple way to express cleanups. C++ code doesn't need
to mess with pthread_cleanup_push; it can just use destructors.
>> > Jason, do you not consider those libraries worth preserving?
>>
>> No, they're already broken.
>
> You answered the question with reference to the C binding.
>
> Defining a C++ binding is the purpose of this list. With an
> appropriately-defined C++ binding, those libraries need not be broken
> *when linked as part of a C++ program*. In other words, you, as a C++
> implementer, have the power to choose whether to preserve or to break
> those C and C++ libraries, regardless of what has been decided for
> the C binding.
On the contrary, these libraries are broken. You are proposing to un-break
them.
Jason
More information about the c++-pthreads
mailing list