Thread + socket = (shared) problem? (2.048)

Bane branimir.milosavljevic at gmail.com
Thu Sep 9 04:08:21 PDT 2010


Thank you for your reply. I have been migrating some socket/thread code from D1 to D2 lately. One of changes is that Thread.this() must have super(&run) in it. It seems when one of the thread doesn't have that line, strange things happen. Can anyone confirm this code to reproduce error:

import std.stdio;
import std.socket;
import core.thread;

class SaboteurThread : Thread {
  this(){
    // super(&run); // comment this line for exception to be thrown when socket is created in other thread
  }
  void run(){
    writeln("Saboteur running");
    while(true){}
  }
}

class SockThread : Thread {
  this(){
    super( &run );
  }

  void run(){
    try {
      auto s = new TcpSocket; // will throw wsock error WSANOTINITIALISED (10093) on windows if SaboteurThread.this() has no super(&run) in it
      writeln("socket created");
    } catch (Exception e){
      writeln(e);
    }
    while(true){}
  }

}

void main(){
  auto x = new SaboteurThread;
  x.start;
  
  auto s = new SockThread;
  s.start;
  
  while(true){}
}



More information about the Digitalmars-d mailing list