Socket.select interrupted system call because of GC

Marek Janukowicz marek at janukowicz.net
Fri Aug 2 23:38:05 PDT 2013


I have a program with one thread waiting on Socket.select call and another 
thread doing stuff causing GC to kick in. When this happens, Socket.select 
fails with "Interrupted system call". I found referenced to some old 
discussion and bug, but it seems to be long gone (I output SA_RESTART in my 
program to make sure it is defined). My program is attached below - it is 
happening on DMD 2.063 on Linux.

import std.socket;
import std.stdio;
import core.thread;
import core.sys.posix.signal;

void serverfunc ()
{
  Socket listener = new TcpSocket ();
  listener.bind (new InternetAddress(1234));
  listener.listen(1);
  SocketSet set = new SocketSet( 1 );
  Socket.select( set, null, null );
  writefln( "last error: %s", lastSocketError() );
}

void clientfunc ()
{
  while( true ) new Object();
}

void main ()
{
  writefln( "sa: %d", SA_RESTART );
  (new Thread (&serverfunc)).start();
  (new Thread (&clientfunc)).start();
}

If I disable GC the problem does not occur.

Any idea how to solve this?

-- 
Marek Janukowicz


More information about the Digitalmars-d-learn mailing list