This is the mail archive of the pthreads-win32@sourceware.cygnus.com mailing list for the pthreas-win32 project.


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

Re: C++ cleanup handler execution


Ross Johnson writes:

> On Wed, 5 Jan 2000, Fred Forester wrote:
>
> > I have a version of pthreads that builds with the new MING egcs 2.9x
> > w/ msvcrt. it C++ exceptions handling seems to be thread safe now. 

I'm playing around with pthreads/C++ exceptions today.  I'm seeing the
following:

Environment: VC++ 6.0 on a NT 4.x box with service pack 5.
             Pthreads-win32 snapshot 1999-11-02
	     I am compiling a C++ program that uses C++ exceptions,
             pthread_cancel(), pthread_cleanup_push(), and
             pthread_cleanup_pop(). 
	     
Also:  I'm not exactly an experienced Windows programmer, so please
       forgive me if anything that I write seems to be odd.

	     	     
I am seeing the following compile errors:

: TcpWriter3.cc
: TcpWriter3.cc(346) : warning C4509: nonstandard extension used: 'run' uses SEH a
: nd '_guard_synch_' has destructor
:         TcpWriter3.cc(341) : see declaration of '_guard_synch_'
: TcpWriter3.cc(379) : warning C4509: nonstandard extension used: 'run' uses SEH a
: nd 'bufStrm' has destructor
:         TcpWriter3.cc(372) : see declaration of 'bufStrm'
: TcpWriter3.cc(379) : warning C4509: nonstandard extension used: 'run' uses SEH a
: nd '_guard_synch_' has destructor
:         TcpWriter3.cc(361) : see declaration of '_guard_synch_'
: TcpWriter3.cc(392) : error C2712: Cannot use __try in functions that require object unwinding

So I went poking around in the code to see what was going on here.  I
ran my code through the preprocessor and noticed that "__try" was
being placed in my code.

So I looked in pthread.h and looked at the following code:
(slightly edited for brevity)

#ifdef _MSC_VER
	/*
	 * WIN32 SEH version of cancel cleanup.
	 */

/* kclark: stuff with __try is here */
...
	 
#else /* _MSC_VER */

#ifndef __cplusplus

	/*
	 * C implementation of PThreads cancel cleanup
	 */

...

#else /* !__cplusplus */

	/*
	 * C++ version of cancel cleanup.
	 * - John E. Bossom.
	 */
...
#endif /* !__cplusplus */

#endif /* _MSC_VER */


Remember, I'm getting the SEH version of the cancel cleanup code.
Now, it is my understanding that I shouldn't be using the SEH stuff in
my C++ environment.

Assuming I'm right about this, I don't know if checking for _MSC_VER
in the code is correct.  The Microsoft VC++ documentation that I have
says that:

: Compiler                           _MSC_VER value
:    --------                           --------------
:    C Compiler version 6.0                  600
:    C/C++ compiler version 7.0              700
:    Visual C++, Windows, version 1.0        800
:    Visual C++, 32-bit, version 1.0         800
:    Visual C++, Windows, version 2.0        900
:    Visual C++, 32-bit, version 2.x         900
:    Visual C++, 32-bit, version 4.0         1000
:    Visual C++, 32-bit, version 5.0         1100
(and I see "1200" with the VC++ 6.x compiler)



After modifying the code a little bit, I am able to get past these
compile errors.  I'm not quite yet at the point where I'm able to run
my test program though.

So I guess my questions are as follows:

1:  is my assumption correct that I shouldn't be using the SEH cleanup
    code in this C++ environment?

2:  If my assumption is correct in question #1, how should the
    "_MSC_VER check" be modified?
        
2:  Are there any obvious caveats that I should look out for when
    using the C++ cleanup code?  For example, while I was playing around
    with this, I changed the definition of this:

#define pthread_cleanup_push( _rout, _arg ) \

        { \

	    PThreadCleanup  cleanup((void (PT_STDCALL *)(void *))(_rout), \

				    (void *) (_arg) );

    to be like this:
				    
#define pthread_cleanup_push( _rout, _arg ) \

        { \

	    PThreadCleanup  cleanup((void (*)(void *))(_rout), \

				    (void *) (_arg) );

				    
because I was having a hard time compiling my code any other way.  Am
I going to get bitten by any subtle calling convention bugs here?
Should I have had to modify this code in the first place? (it compiles
and runs fine on Solaris and Linux)


Assuming that I get this working, of course I will be more than glad
to provide you with any changes that I made to the code.


Thanks for any assistance you can provide!  And thanks for such a
high-quality pthreads implementation!

--kevin
-- 
Kevin D. Clark          |                          |
kclark@NOSPAM.ctron.com | kdcNOSPAM@alumni.unh.edu |  Give me a decent UNIX
Cabletron Systems, Inc. | PGP Key Available        | and I can move the world
Durham, N.H. (USA)      |                          |

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