public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
* About exit4.c
@ 2002-02-23 21:53 Pietrobon Marcello
  2002-02-23 22:39 ` Pietrobon Marcello
  0 siblings, 1 reply; 3+ messages in thread
From: Pietrobon Marcello @ 2002-02-23 21:53 UTC (permalink / raw)
  To: Pthreads Developers List; +Cc: Ross Johnson

[-- Attachment #1: Type: text/plain, Size: 2306 bytes --]

I am using the cvs of pthreads downloaded the 2002-02-23 [09:00am]

I tried to find the reason of the problem with test\exit4.c
Essentially, as you know, is the fact that when an exception is thrown
and the stack is unwound the destructor of an object allocated in the
stack is not called even if the object is destroyed (I don't see any
memory leak).

I found some interesting results:

1) If  throw ptw32_exception_exit(); or  pthread_exit(arg); is called
from within func() in the module exit4.h, that the destructor IS called

2) If pthread_exit() is called from within an auxiliary function inside
exit.c, where also pthread_exit() is, than the destructor is still NOT
called.

3) If an object is declared in thread.h (as I did with
pthread_CheckDestructor) ad instantiated inside func() in exit4.c (like
the Guard object),  than its destructor IS called.

4) If I compile exit4.c and pthread.c together (so I don't use any
library, either static or dynamic) than the behaviour above doesn't
change.
So the problem is not due to some DLL's address space issues.

5) Compiling with icl5 and icl6 (Intel compiler) the problem does not
exist in any case.

6) If the obj files are created by the Intel compiler, but directly
linked by the linker of Visual studio (link.exe), than the problem does
not exist in any case.
(to verify this I created the batch files tc.bat and tl.bat)

I tried to find some workarounds but I couldn't, maybe you can do it
with these informations.

I created some dsp projects (Visual Studio 6) and vjproj (Visual Studio
solutions) to make my life easier.
pthreads_dll.dsp, pthreads_lib.dsp to create a dynamic and a static
library

I also slightly modified the makefiles in order to easily switch between
the Microsoft compiler (vc) and the Intel compiler (icl).

I am sending as attachment the zip files used for this testing.
I am available for any further clarifications.

Best Regards,
Marcello

P.S.
While compiling the library there is a warning:
d:\Programming\MyProjects\C++\Libraries\Pthreads-Win32\Pthreads-Active\ptw32_threadStart.c(309)
: warning C4297: 'ptw32_threadStart' : function assumed not to throw an
exception but does
        __declspec(nothrow) or throw() was specified on the function
but I don't know why is created and why only compiling private.c



[-- Attachment #2: pthreads-2002-02-23 [09&00am]_sent.zip --]
[-- Type: application/x-unknown-content-type-BitZipper, Size: 536176 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: About exit4.c
  2002-02-23 21:53 About exit4.c Pietrobon Marcello
@ 2002-02-23 22:39 ` Pietrobon Marcello
  0 siblings, 0 replies; 3+ messages in thread
From: Pietrobon Marcello @ 2002-02-23 22:39 UTC (permalink / raw)
  To: Pthreads Developers List

Even if it is not important It might be good to know about an other bug (probably) of the Microsoft compiler (which I
discovered trying to fix the problem with exit4.c):

The following code:
----------------------------------
#include <stdio.h>

class CheckDestructor
{
public:
 CheckDestructor() { printf("CheckDestructor"); };
 ~CheckDestructor() { printf("~CheckDestructor"); };
};

void f()
{
 CheckDestructor check;
 throw 1;
}

int main(int argc, char* argv[])
{
 //try
 //{
  f();
 //}
 //catch (...) {
 // printf("inside catch(...)\n");
 //}
 return 0;
}
----------------------------------

doens't call the destructor ~CheckDestructor().
But it does that if we put f() inside the try... catch block

The reason is that main() is called from crt0.c inside a __try ... __except block, which does not call the destructor.

This violates the Ansi C++ specification dec96: see
http://www.codeproject.com/cpp/ANSI-cpp-dec96/except.asp
where 15.2  Constructors and destructors                       [except.ctor].

Best Regards,
Marcello

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: About exit4.c
@ 2002-02-25  3:14 Alexander Terekhov
  0 siblings, 0 replies; 3+ messages in thread
From: Alexander Terekhov @ 2002-02-25  3:14 UTC (permalink / raw)
  To: Pthreads Developers List


[...uncaught exceptions...]

> This violates the Ansi C++ specification...

Nope.

FYI:

http://groups.google.com/groups?as_umsgid=3C75280D.571C0C0A%40web.de
http://groups.google.com/groups?as_umsgid=3C7633AF.4A08EFBF%40web.de
http://groups.google.com/groups?as_umsgid=3C741E98.BFA02412%40web.de
http://groups.google.com/groups?as_umsgid=3C77AFCB.481D2587%40web.de

regards,
alexander.


Pietrobon Marcello <teiffel@attglobal.net>@sources.redhat.com on 02/24/2002
07:38:55 AM

Sent by:  pthreads-win32-owner@sources.redhat.com


To:   Pthreads Developers List <pthreads-win32@sourceware.cygnus.com>
cc:
Subject:  Re: About exit4.c



Even if it is not important It might be good to know about an other bug
(probably) of the Microsoft compiler (which I
discovered trying to fix the problem with exit4.c):

The following code:
----------------------------------
#include <stdio.h>

class CheckDestructor
{
public:
 CheckDestructor() { printf("CheckDestructor"); };
 ~CheckDestructor() { printf("~CheckDestructor"); };
};

void f()
{
 CheckDestructor check;
 throw 1;
}

int main(int argc, char* argv[])
{
 //try
 //{
  f();
 //}
 //catch (...) {
 // printf("inside catch(...)\n");
 //}
 return 0;
}
----------------------------------

doens't call the destructor ~CheckDestructor().
But it does that if we put f() inside the try... catch block

The reason is that main() is called from crt0.c inside a __try ... __except
block, which does not call the destructor.

This violates the Ansi C++ specification dec96: see
http://www.codeproject.com/cpp/ANSI-cpp-dec96/except.asp
where 15.2  Constructors and destructors
[except.ctor].

Best Regards,
Marcello




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-02-25 11:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-23 21:53 About exit4.c Pietrobon Marcello
2002-02-23 22:39 ` Pietrobon Marcello
2002-02-25  3:14 Alexander Terekhov

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