public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
From: "Kevin D. Clark" <kclark@cabletron.com>
To: Ross Johnson <rpj@ise.canberra.edu.au>
Cc: Fred Forester <fforest@eticomm.net>,
	Pthreads Developers List <pthreads-win32@sourceware.cygnus.com>
Subject: Re: C++ cleanup handler execution
Date: Thu, 06 Jan 2000 14:11:00 -0000	[thread overview]
Message-ID: <14453.4956.759854.712859@cabletron.com> (raw)
In-Reply-To: <Pine.LNX.4.05.10001061023190.15776-100000@swan.ise.canberra.edu.au>

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)      |                          |

  reply	other threads:[~2000-01-06 14:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <000601bf578e$3c89a750$208e08d0@fflaptop>
2000-01-05 17:35 ` Ross Johnson
2000-01-06 14:11   ` Kevin D. Clark [this message]
2000-01-06 18:17     ` Ross Johnson
2000-01-14  8:19       ` Kevin D. Clark
2000-01-14  8:27         ` Kevin D. Clark
2000-01-14  8:30           ` Kevin D. Clark
2000-01-14  8:36           ` Kevin D. Clark
2000-02-02 10:08             ` pthread_cancel() problems Kevin D. Clark
2000-06-14 18:06         ` Question about condition variable Taci Ãœlker
     [not found]           ` <3949054F.3127@surfnshop.com>
2000-06-16  7:33             ` Taci Ãœlker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=14453.4956.759854.712859@cabletron.com \
    --to=kclark@cabletron.com \
    --cc=fforest@eticomm.net \
    --cc=pthreads-win32@sourceware.cygnus.com \
    --cc=rpj@ise.canberra.edu.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).