| Thread overview | ||||||
|---|---|---|---|---|---|---|
|
January 23, 2015 why spawn crash? | ||||
|---|---|---|---|---|
| ||||
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()
| ||||
January 23, 2015 Re: why spawn crash? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to mzfhhhh | 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
| |||
January 24, 2015 Re: why spawn crash? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | 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!
| |||
February 08, 2015 Re: why spawn crash? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to mzfhhhh | 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");
}
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply