Bug 2242 – linux system calls are canceled by GC

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2008-07-24T05:09:00Z
Last change time
2015-06-09T01:21:35Z
Keywords
wrong-code
Assigned to
bugzilla
Creator
gide

Comments

Comment #0 by gide — 2008-07-24T05:09:23Z
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.bugs&article_id=14685 > On Tue, 22 Jul 2008 09:50:06 -0400, shinichiro.h wrote: Hi D guys, The following program import std.stream; import std.cstream; import std.thread; class ReaderThread : Thread { override int run() { char[] line = din.readLine(); dout.writeLine(line); return 0; } } void main() { ReaderThread rt = new ReaderThread(); rt.start(); for (int i = 0; i < 100000; i++) { new Object; } rt.wait(); } works as intended on Windows (suppose a scenario in which a user may input a line after the for-loop): 1. Start ReaderThread 2. 100000 allocations 3. a user input a line 4. show the line and finish ReaderThread 5. the program finishes but doesn't work on Linux 1. Start ReaderThread 2. 100000 allocations 3. during the allocations, GC is invoked and SIGUSR1 is issued to stop the world 4. the SIGUSR1 makes read system call fail (errno=EINTR) 5. the program outputs empty line and finishes without waiting the user's input. this issue is serious when we are writing network applications (synchronous accept(2) or read(2) fail often). The following super short patch will fix the problem: --- /usr/local/dmd/src/phobos/std/thread.d 2008-04-28 06:00:52.000000000 +0900 +++ thread.d 2008-07-22 03:21:11.000000000 +0900 @@ -1044,6 +1044,7 @@ if (result) goto Lfail; sigact.sa_handler = &pauseHandler; + sigact.sa_flags = 0x10000000u /* SA_RESTART */; result = sigaction(SIGUSR1, &sigact, null); if (result) goto Lfail; you may want to put SA_RESTART in somewhere else (supposedly, std.c.linux.linux?) though. I believe tango doesn't have this problem since its Thread.d seems to set SA_RESTART. I hope this patch is accepted in near future. I'm using dmd-2.014.
Comment #1 by bugzilla — 2008-08-14T03:01:08Z
Fixed dmd 1.034 and 2.018