Statically initialising pthread attributes in dynamic dlls.

Andrew West andrewwest@gmail.com
Tue Feb 23 10:01:00 GMT 2010


On 22/02/2010 17:36, Dave Korn wrote:
> On 22/02/2010 10:33, Andrew West wrote:
>    
>> 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
>>      
>    You must have accidentally omitted "-shared" here, since it wouldn't link
> otherwise.
>
>    
Yep.

>> The only other bits of information I can give which might or might not
>> be helpful are;
>>      
>    Run "cygcheck -s -r -v>  cygcheck.out" and then send that to the list *as an
> attachment* (i.e. not inline in the body text).  TIA!
>
>      cheers,
>        DaveK
>
>    

Oh sorry about that, my mail client should be fixed now, see attached ( 
I hope ) cygcheck.out.

Looking through the cygwin code the first thing pthread_mutexattr_init 
does is check to see if the attribute
passed in is 'is_good_object( attr )', which eventually gets to 
'verifyable_object_isvalid' and this line;

if ((*object)->magic != magic)

As object hasn't been initialised yet ( it's initialised after this 
check ) so doing this
dereference causes windows to throw a STATUS_ACCESS_VIOLATION. Under 
normal circumstances
the clever cygtls stuff should catch this using it's exception handler 
installed at the start of the SEH, and allow
cygwin to continue and properly initialise the thread mutex attribute 
object.

With the code I'm testing against, the exception handler isn't called in 
the library and it bombs out there. :(
The dll initialisation stuff calls '_cygtls::init_exception_handler' but 
it doesn't insert it because it finds it's already
there ( from test.exe I guess ), or at least it doesn't hit my break 
point in '_cygtls::reset_fault' during the call
to pthread_mutexattr_init.

Andy.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cygcheck.out
URL: <http://cygwin.com/pipermail/cygwin/attachments/20100223/e1ac6401/attachment.ksh>
-------------- next part --------------
--
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


More information about the Cygwin mailing list