public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
* cleanup.c problem? - vanilla C implementation
@ 1999-06-02  1:56 Todd Owen
  0 siblings, 0 replies; only message in thread
From: Todd Owen @ 1999-06-02  1:56 UTC (permalink / raw)
  To: pthreads-win32

hi, I'm trying to build an application with mingw32 (with the MSVCRT add-on), using the MSVC-compiled DLL.  I think I've found a problem in cleanup.c which is causing some strange behaviour.

Because I'm compiling in plain C, pthread.h will supply me the implementation of pthread_cleanup_push/pop which use the pthread_push/pop_cleanup functions in the DLL.  These functions (in cleanup.c) both have little bits which are included only when compiled without _MSC_VER and __cplusplus, for instance pthread_pop_cleanup has:

#if !defined(_MSC_VER) && !defined(__cplusplus)

      pthread_setspecific (_pthread_cleanupKey, (void *) cleanup->prev);

#endif /* !_MSC_VER && !__cplusplus */

The DLL has been compiled with MSVC, therefore this bit is excluded, but I believe it _is_ required.  Even if I compiled my app with MSVC but used the implementation of pthread_cleanup_push/pop which calls these functions (this wouldn't happen, of course, pthread.h would supply a different alternative, but lets pretend), I believe it would still be wrong.
Thus: I think the #if/#endif lines should be removed entirely.  In both functions.

Well, I might as well include a little prog I used to test.  With linuxthreads, the output is:

cleanup called, arg == Apple: depth 1
cleanup called, arg == Banana: depth 2
cleanup called, arg == Banana: depth 1
No carrots today...

With pthreads-win32, COMPILED WITH MINGW32 and linked to msvc compiled DLL, the output is:

cleanup called, arg == Apple: depth 1
cleanup called, arg == Banana: depth 2
cleanup called, arg == Banana: depth 2   <<<<<<< cleanup called twice!
No carrots today...


*****************cut here***********************
#include <pthread.h>
#include <stdio.h>

void cleanup(void *arg) {
  printf("cleanup called, arg == %s\n", (char *) arg);
}

void main() {
  pthread_cleanup_push(cleanup, "Apple: depth 1");
  pthread_cleanup_pop(1);

  pthread_cleanup_push(cleanup, "Banana: depth 1");
  pthread_cleanup_push(cleanup, "Banana: depth 2");
  pthread_cleanup_pop(1);
  pthread_cleanup_pop(1);
  
  printf("No carrots today...\n");
}


....................please cut here....................
 
Todd Owen <towen@nw.com.au>
 
=== Netway Technologies ===
http://www.nw.com.au

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1999-06-02  1:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-06-02  1:56 cleanup.c problem? - vanilla C implementation Todd Owen

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