www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - why spawn crash?

reply "mzfhhhh" <mzfhhhh foxmail.com> writes:
i wrote a test code:

void worker(int firstNumber)
{
      Thread.sleep(1.msecs);
}

void main()
{
     foreach (i; 1 .. 1000) {
         spawn(&worker, i );
         writeln(i);
     }
     thread_joinAll();
     writeln("ok");
}


sometimes it's ok,sometimes it's crashed ! why ?
here is one of times callstack message:

  	test.exe!_free()	
  	test.exe!_fwide()	
  	test.exe!_fwide()	
  	test.exe!__ReleaseSemaphore()	
  	test.exe!_fwide()	
	test.exe!main __modctor() 行 3
test.exe!rt minfo __T14runModuleFuncsS482rt5minfo11ModuleGroup11runTlsCtorsMFZ9__lambda1Z runModuleFuncs() test.exe!___threadstartex 4()
Jan 22 2015
parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On 1/22/15 10:20 PM, mzfhhhh wrote:
 i wrote a test code:

 void worker(int firstNumber)
 {
       Thread.sleep(1.msecs);
 }

 void main()
 {
      foreach (i; 1 .. 1000) {
          spawn(&worker, i );
          writeln(i);
      }
      thread_joinAll();
      writeln("ok");
 }


 sometimes it's ok,sometimes it's crashed ! why ?
 here is one of times callstack message:

       test.exe!_free()
       test.exe!_fwide()
       test.exe!_fwide()
       test.exe!__ReleaseSemaphore()
       test.exe!_fwide()
     test.exe!main __modctor() 行 3
test.exe!rt minfo __T14runModuleFuncsS482rt5minfo11ModuleGroup11runTlsCtorsMFZ9__lambda1Z runModuleFuncs() test.exe!___threadstartex 4()
That sounds like a bug in stdio. fwide is the horrible attempt of C stdio to do wide character output. -Steve
Jan 23 2015
parent reply "mzfhhhh" <mzfhhhh foxmail.com> writes:
thanks,you are right.

window console show chinese char is not right,
so i try to add this code:
"
extern(C) int setlocale(int, char*);
static this()
{
     fwide(core.stdc.stdio.stdout, 1);
     setlocale(LC_CTYPE, cast(char*)"china");
}
"
it's looks like solve the problem,but caused another problem.

now i use "chcp 65001" command to change the code page and change 
the
font to "lucida console".it works correctly!
Jan 23 2015
parent "mzfhhhh" <mzfhhhh foxmail.com> writes:
On Saturday, 24 January 2015 at 01:54:32 UTC, mzfhhhh wrote:
 thanks,you are right.

 window console show chinese char is not right,
 so i try to add this code:
 "
 extern(C) int setlocale(int, char*);
 static this()
 {
     fwide(core.stdc.stdio.stdout, 1);
     setlocale(LC_CTYPE, cast(char*)"china");
 }
 "
 it's looks like solve the problem,but caused another problem.

 now i use "chcp 65001" command to change the code page and 
 change the
 font to "lucida console".it works correctly!
this way also have problem! look this bug report: Issue 13651 - Writing Unicode text with console code page 65001 (UTF-8) may fail now,i use this code show string on window console: void write(string s) { import std.windows.charset:toMBSz; printf(toMBSz(s)); } void writeln(string s) { write(s); printf("\r\n"); }
Feb 08 2015