From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29576 invoked by alias); 19 Dec 2012 01:00:33 -0000 Received: (qmail 29300 invoked by uid 22791); 19 Dec 2012 01:00:29 -0000 X-SWARE-Spam-Status: No, hits=-0.1 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-ob0-f176.google.com (HELO mail-ob0-f176.google.com) (209.85.214.176) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 19 Dec 2012 01:00:23 +0000 Received: by mail-ob0-f176.google.com with SMTP id un3so1377253obb.35 for ; Tue, 18 Dec 2012 17:00:22 -0800 (PST) MIME-Version: 1.0 Received: by 10.60.31.84 with SMTP id y20mr3383165oeh.91.1355878822425; Tue, 18 Dec 2012 17:00:22 -0800 (PST) Received: by 10.76.170.234 with HTTP; Tue, 18 Dec 2012 17:00:22 -0800 (PST) Reply-To: wim.delvaux@adaptiveplanet.com Date: Wed, 19 Dec 2012 01:00:00 -0000 Message-ID: Subject: Mingw32 : issue with atexit function in main thread From: Wim Delvaux To: pthreads-win32@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes Mailing-List: contact pthreads-win32-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: pthreads-win32-owner@sourceware.org X-SW-Source: 2012/txt/msg00039.txt.bz2 Hi all, I have this C - program that uses a dll library of my own, originally created on a Linux platform. This DLL library creates some internal threads. The main program does not know of the existence of these threads. To cleanup these threads (and other resources), the current implementation of that library registers a cleanup function using the atexit C function. The idea is that when the program returns from main after it has finished doing its business, the library gets the last word to do its own cleanup work. What happens in Mingw is that the internal threads is still alive just before the return from main but somewhere between the return and the call of atexit cleanup function, the threads are stopped. I checked the source code of pthread and I think it has something to do with the pthread_win32_process_detach_np function that gets executed when the pthread dll gets unloaded ( or something like that). Is there any way I can reproduce get the atexit behavior i.e. that the cleanup function gets called *before* the threads are terminated by the pthread dll ? Or is there another (non portable ?) way I can register a cleanup function to the mingw specific pthread implementation by not using atexit but something else ? And of course ... how can I do this ? Any help appreciated Wim