2242 – linux system calls are canceled by GC

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2242 - linux system calls are canceled by GC
Summary: linux system calls are canceled by GC
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Linux
: P2 normal
Assignee: Walter Bright
URL:
Keywords: wrong-code
Depends on:
Blocks:
Reported: 2008年07月24日 05:09 UTC by Gide Nwawudu
Modified: 2015年06月09日 01:21 UTC (History)
0 users

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Gide Nwawudu 2008年07月24日 05:09:23 UTC
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.bugs&article_id=14685
> On 2008年7月22日 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 Walter Bright 2008年08月14日 03:01:08 UTC
Fixed dmd 1.034 and 2.018


AltStyle によって変換されたページ (->オリジナル) /