This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Cancelling threads and C++ (LinuxThreads)

I've been working on a medium-sized C++ program that uses pthreads and runs on
Linux.  FYI:  I'm running Linux kernel 2.2.10ac3 and glibc 2.0.7 that came on
the Mandrake CD set on an x86 system.

The issue that I have to bring to attention is cancellation of threads in the
presence of a C++ program in deferred cancellation mode.  When a thread is
cancelled, the destructors for stack-based objects are not called.

I've got a work-around, and a request for future versions of glibc/LinuxThreads.

First, the work-around:

        At the start of the thread function, I push a cancellation handler
        which throws an exception.  This exception is caught in the top-level
        of the thread function, and the catch() clause calls

        To make this work right, I had to recompile glibc with -fexceptions. 
        I'm using egcs 1.1.2 to do this.

This work-around works.  However, I've corresponded with Dave Butenhof, who
wrote "Programming with POSIX Threads".  His opinion was that this solution
isn't portable, and that the library implementing pthreads should see to it
that destructors for stack-based objects are called without my program having
to do anything special.

So, my question(s) would be:

        Is a patch to LinuxThreads to implement the throw/catch mechanism
        for cancelling threads appropriate?  This would include the -fexceptions
        compile option for the entire C library.

        I could probably supply a patch if I played around with this long
        enough.  Is it appropriate to include C++ code in the C library?

        Is a patch like this in the works already, or implemented in a version
        that I don't have yet?

        Would this require that a single mechanism for exceptions be used,
        rather than the two that are available in egcs now?  (-fnew-exceptions
        vs. -fsjlj-exceptions)

Thank you for your time.
George T. Talbot

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]