www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Aborting from core/sync/mutex.d(147) Error: pthread_mutex_init failed.

reply mitchell <mitchelldlarson pm.me> writes:
Hello,

I've just finished migrating a project from GDC/Makefile to LDC 
with dub. The program now compiles and runs, and works fine until 
such time as the following error occurs:

Aborting from core/sync/mutex.d(147) Error: pthread_mutex_init 
failed.

out of GDB, the whole text is:

Aborting from core/sync/mutex.d(147) Error: pthread_mutex_init 
failed.
Thread 1 "squares" received signal SIGABRT, Aborted.
[Switching to Thread 0x7ffff74a7580 (LWP 7576)]
__GI_raise (sig=sig entry=6) at 
../sysdeps/unix/sysv/linux/raise.c:50
50	../sysdeps/unix/sysv/linux/raise.c: No such file or directory.

and the backtrace is (sorry for info dump):


../sysdeps/unix/sysv/linux/raise.c:50


_D4core8internal5abortQgFNbNiNfMAyaMQemZv ()
    from /lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

    from /lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

/lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

_D2gc4impl12conservativeQw3Gcx5sweepMFNbZm ()
    from /lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

_D2gc4impl12conservativeQw3Gcx11fullcollectMFNbbZm ()
    from /lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

_D2gc4impl12conservativeQw3Gcx10smallAllocMFNbhKmkZPv ()
    from /lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

_D2gc4impl12conservativeQw14ConservativeGC__T9runLockedS_DQCeQCeQCcQCnQBs12mallocNoSyncMFNbmkKmxC8TypeInfoZPvS_DQEgQEgQEeQEp10mallocTimelS_DQFiQFiQFgQFr10numMallocslTmTkTmTxQCzZQF
MFNbKmKkKmKxQDsZQDl () from /lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

_DThn16_2gc4impl12conservativeQw14ConservativeGC6qallocMFNbmkxC8TypeInfoZS4
ore6memory8BlkInfo_ () from /lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

/lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

_D4core6memory2GC6qallocFNaNbmkxC8TypeInfoZSQBqQBo8BlkInfo_ ()
    from /lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

/lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

_D7squares4core5coord5Coord9adjacentsMxFNdZASQBrQBmQBkQBh 
(this=...)
     at 
/home/mitchell/Apps/D/games/squares/src/squares/core/coord.d:102


of "my" code, and the deeper ones (appear?) to be runtime and 
phobos stuff.The lines immediately around coord.d:102 are:

     Coord[] adjacents() const  property
     {
         return [ right, up, left, down ]; // line 102
     }

which are defined in a struct called "Coord". I suspect that 
there isn't something wrong specifically with this line, and 
instead something more "amazingly" wrong. Given that this worked 
fine with the previous (and older) version of GDC which I used 
before my migration, I don't know what could be wrong.

I'm just not entirely certain where to start looking for 
problems. If this issue is over-broad, I'm sorry. Elsewhere in 
the program, I make use of the core.thread and Thread things, 
however that implementation seems fairly straightforward and 
fine, and never had issues under the old compiler.

Any and all help is appreciated!
Mar 31 2020
parent mitchell <mitchelldlarson pm.me> writes:
On Wednesday, 1 April 2020 at 02:08:09 UTC, mitchell wrote:
 Hello,

 I've just finished migrating a project from GDC/Makefile to LDC 
 with dub. The program now compiles and runs, and works fine 
 until such time as the following error occurs:

 Aborting from core/sync/mutex.d(147) Error: pthread_mutex_init 
 failed.

 out of GDB, the whole text is:

 Aborting from core/sync/mutex.d(147) Error: pthread_mutex_init 
 failed.
 Thread 1 "squares" received signal SIGABRT, Aborted.
 [Switching to Thread 0x7ffff74a7580 (LWP 7576)]
 __GI_raise (sig=sig entry=6) at 
 ../sysdeps/unix/sysv/linux/raise.c:50
 50	../sysdeps/unix/sysv/linux/raise.c: No such file or 
 directory.

 and the backtrace is (sorry for info dump):


 ../sysdeps/unix/sysv/linux/raise.c:50


 _D4core8internal5abortQgFNbNiNfMAyaMQemZv ()
    from /lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

    from /lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

 /lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

 _D2gc4impl12conservativeQw3Gcx5sweepMFNbZm ()
    from /lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

 _D2gc4impl12conservativeQw3Gcx11fullcollectMFNbbZm ()
    from /lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

 _D2gc4impl12conservativeQw3Gcx10smallAllocMFNbhKmkZPv ()
    from /lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

 _D2gc4impl12conservativeQw14ConservativeGC__T9runLockedS_DQCeQCeQCcQCnQBs12mallocNoSyncMFNbmkKmxC8TypeInfoZPvS_DQEgQEgQEeQEp10mallocTimelS_DQFiQFiQFgQFr10numMallocslTmTkTmTxQCzZQF
MFNbKmKkKmKxQDsZQDl () from /lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

 _DThn16_2gc4impl12conservativeQw14ConservativeGC6qallocMFNbmkxC8TypeInfoZS4
ore6memory8BlkInfo_ () from /lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

 /lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

 _D4core6memory2GC6qallocFNaNbmkxC8TypeInfoZSQBqQBo8BlkInfo_ ()
    from /lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

 /lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.82

 _D7squares4core5coord5Coord9adjacentsMxFNdZASQBrQBmQBkQBh 
 (this=...)
     at 
 /home/mitchell/Apps/D/games/squares/src/squares/core/coord.d:102


 line of "my" code, and the deeper ones (appear?) to be runtime 
 and phobos stuff.The lines immediately around coord.d:102 are:

     Coord[] adjacents() const  property
     {
         return [ right, up, left, down ]; // line 102
     }

 which are defined in a struct called "Coord". I suspect that 
 there isn't something wrong specifically with this line, and 
 instead something more "amazingly" wrong. Given that this 
 worked fine with the previous (and older) version of GDC which 
 I used before my migration, I don't know what could be wrong.

 I'm just not entirely certain where to start looking for 
 problems. If this issue is over-broad, I'm sorry. Elsewhere in 
 the program, I make use of the core.thread and Thread things, 
 however that implementation seems fairly straightforward and 
 fine, and never had issues under the old compiler.

 Any and all help is appreciated!
I have (surprisingly) figured out the issue myself. I guess I didn't think about this before, but the background thread (elsewhere in the application) keeps a few mutexes such that it can pass work to the main thread (for changing UI things, and such) and it appears that after the background task is completed, there is at least one mutex which was still held in a locked state. The error arises (as can been seen from the stack trace) when that mutex is being destructed. As my underlying system is unix, the pthread object beneath mutex is destroyed, but according to the documentation (https://linux.die.net/man/3/pthread_mutex_destroy) destroying a mutex while it's still locked can cause an error. After I fixed my implementation to ensure that all mutexes are unlocked on the appropriate threads before they can be destructed, the issue went away. Apparently my old compiler either handled that issue for me automatically, or it just wasn't being detected. TLDR: pebkac
Apr 01 2020