delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/02/22/05:33:25

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00
X-Spam-Check-By: sourceware.org
Message-ID: <4B825D76.6000105@gmail.com>
Date: Mon, 22 Feb 2010 10:33:26 +0000
From: Andrew West <andrewwest AT gmail DOT com>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.7) Gecko/20100111 Thunderbird/3.0.1
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Statically initialising pthread attributes in dynamic dlls.
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

--------------030409040604020408010900
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Trying to initialise a pthread attribute in a static variable seems to 
cause a segfault. I've attach a simple test case compiled using;

g++ -g mutex.cpp -o mutex.dll -lpthread
g++ -g test.cpp -o test.exe -ldl

I've cropped the code down to the essential bits, so no error reporting 
if it can't find the dll, etc.

The only other bits of information I can give which might or might not 
be helpful are;

1) Calling pthread_mutexattr_init in a static variable in the executable 
works.
2) If I remove the pthread_mutexattr_init/pthread_mutexattr_destroy 
calls it works.
3) Delaying the pthread_mutexattr_init call until the first time the 
Mutex class is used works BUT then the
segfault happens when dlclose is called.

I haven't managed to track down the cause of the segfault yet, I'm 
getting a bit lost in the debugger :/

Andy

--------------030409040604020408010900
Content-Type: text/plain;
 name="mutex.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="mutex.cpp"

#include <dlfcn.h>
#include <pthread.h>
#include <stdio.h>

struct Mutex {
  Mutex()
  {
    pthread_mutexattr_init( &_attr );
    pthread_mutexattr_settype( &_attr, PTHREAD_MUTEX_RECURSIVE );
    pthread_mutex_init( &_mutex, &_attr );
  }
  ~Mutex()
  {
    pthread_mutex_destroy( &_mutex );
    pthread_mutexattr_destroy( &_attr );
  }
protected:
  pthread_mutex_t _mutex;
  pthread_mutexattr_t _attr;
};

static Mutex mymutex;

void __EntryPoint()
{
  printf( "In mutex.dll\n" );
}

--------------030409040604020408010900
Content-Type: text/plain;
 name="test.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="test.cpp"

#include <dlfcn.h>

int main( int argc, char** argv )
{
  void* dll = dlopen( "mutex.dll", RTLD_NOW );
  dlclose( dll );
}


--------------030409040604020408010900
Content-Type: text/plain; charset=us-ascii

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
--------------030409040604020408010900--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019