www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Invoking writeln() from a lot of threads running concurrently -->

reply IM <3di gm.com> writes:
For purposes of debugging, I'm using writeln() to print stuff out 
from tasks running concurrently on many threads. At some point it 
crashes with the following stack trace:

Thread 4 received signal SIGUSR1, User defined signal 1.
[Switching to Thread 0x7ffff5ec2700 (LWP 19267)]
__lll_lock_wait_private () at 
../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:95
95	../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S: No such file 
or directory.
(gdb) bt

../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:95

<_IO_stdfile_1_lock>) at ../sysdeps/pthread/flockfile.c:28

_D3std5stdio4File17LockingTextWriter6__ctorMFNcNeKSQBxQBwQBtZSQCiQChQCeQCc ()

_D3std5stdio4File17lockingTextWriterMFNfZSQBoQBnQBk17LockingTextWriter ()

_D3std5stdio4File__T5writeTAyaTyiTaZQqMFNfQpyiaZv (this=..., 
_param_2=10 '\n', _param_1=12, _param_0=...)
     at /usr/include/dmd/phobos/std/stdio.d:1399

Note that I didn't add any synchronizations around the writeln() 
calls, should I? I assume the implementation *should* synchronize 
access to std_out, no?

Bug in phobos?
Dec 09 2017
next sibling parent reply Messenger <dont shoot.me> writes:
On Saturday, 9 December 2017 at 09:38:05 UTC, IM wrote:
 For purposes of debugging, I'm using writeln() to print stuff 
 out from tasks running concurrently on many threads. At some 
 point it crashes with the following stack trace:

 Thread 4 received signal SIGUSR1, User defined signal 1.
[...]
 Bug in phobos?
Is that a crash or just thread 4 receiving SIGUSR1? (GC signal) If so you just need to tell gdb not to stop on that. ("handle SIGUR1 SIGUSR2 nostop", place it in ~/.gdbinit)
Dec 09 2017
next sibling parent IM <3di gm.com> writes:
On Saturday, 9 December 2017 at 10:36:08 UTC, Messenger wrote:
 On Saturday, 9 December 2017 at 09:38:05 UTC, IM wrote:
 For purposes of debugging, I'm using writeln() to print stuff 
 out from tasks running concurrently on many threads. At some 
 point it crashes with the following stack trace:

 Thread 4 received signal SIGUSR1, User defined signal 1.
[...]
 Bug in phobos?
Is that a crash or just thread 4 receiving SIGUSR1? (GC signal) If so you just need to tell gdb not to stop on that. ("handle SIGUR1 SIGUSR2 nostop", place it in ~/.gdbinit)
Thanks! That works!
Dec 09 2017
prev sibling parent Mengu <mengukagan gmail.com> writes:
On Saturday, 9 December 2017 at 10:36:08 UTC, Messenger wrote:
 On Saturday, 9 December 2017 at 09:38:05 UTC, IM wrote:
 For purposes of debugging, I'm using writeln() to print stuff 
 out from tasks running concurrently on many threads. At some 
 point it crashes with the following stack trace:

 Thread 4 received signal SIGUSR1, User defined signal 1.
[...]
 Bug in phobos?
Is that a crash or just thread 4 receiving SIGUSR1? (GC signal) If so you just need to tell gdb not to stop on that. ("handle SIGUR1 SIGUSR2 nostop", place it in ~/.gdbinit)
i've been bitten many times by this. thanks to the folks on irc, it now lives in gdbinit.
Dec 10 2017
prev sibling parent reply Seb <seb wilzba.ch> writes:
On Saturday, 9 December 2017 at 09:38:05 UTC, IM wrote:
 Note that I didn't add any synchronizations around the 
 writeln() calls, should I? I assume the implementation *should* 
 synchronize access to std_out, no?

 Bug in phobos?
Yes, try using synchronized access. IIRC the implementation of LockingTextWriter isn't thread-safe.
Dec 09 2017
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 12/9/2017 5:56 AM, Seb wrote:
 IIRC the implementation of LockingTextWriter 
 isn't thread-safe.
There's no bugzilla issue on this. So I added one: https://issues.dlang.org/show_bug.cgi?id=18052 Please, folks, I can't emphasize this enough. When you find a bug, POST IT ON BUGZILLA! Otherwise, it will NEVER get fixed.
Dec 09 2017
parent IM <3di gm.com> writes:
On Sunday, 10 December 2017 at 01:12:37 UTC, Walter Bright wrote:
 On 12/9/2017 5:56 AM, Seb wrote:
 IIRC the implementation of LockingTextWriter isn't thread-safe.
There's no bugzilla issue on this. So I added one: https://issues.dlang.org/show_bug.cgi?id=18052 Please, folks, I can't emphasize this enough. When you find a bug, POST IT ON BUGZILLA! Otherwise, it will NEVER get fixed.
I was going to file one, but I wanted to verify first that it's seem to be one if SIGUSR1 is a GC signal. I was trying to debug a crash in gdb and that one kept showing up. After adding handle SIGUSR1 SIGUSR2 nostop I was able to capture the real issue. Sorry for the false positive --- still learning about D! :( I think we can probably close that bug.
Dec 09 2017