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]

cleanup.c problem? - vanilla C implementation


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


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