D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6463 - Segfault on writeln() from a Fiber
Summary: Segfault on writeln() from a Fiber
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-10 03:10 UTC by Danny Arends
Modified: 2011-08-17 09:04 UTC (History)
1 user (show)

See Also:


Attachments
Segfault from fiber (494 bytes, text/plain)
2011-08-16 01:02 UTC, Danny Arends
Details

Note You need to log in before you can comment on or make changes to this issue.
Description Danny Arends 2011-08-10 03:10:21 UTC
Trying to print floats and doubles from a fiber it fails with a 
segfault, while it is possible to do the same in the main thread. 

The expected output of the attached code file: 
15 
15 
Done 

However I get: 
15 
segfault 

I am using the DMD64 D Compiler v 2.054 on Debian 64 

What am I doing wrong, because using to!string() on the floats and 
double allows me to print them to std.out. 

I however get weird behavior when I try to do math on the floats and 
doubles in the fiber, or when I pass them to C-functions. 

Kind regards, 
Danny
Comment 1 Danny Arends 2011-08-11 06:21:47 UTC
Tested on other systems: 32bit Debian Squeeze and Win32, this does not happen and I get the expected output of:
15
15
Done
Comment 2 Martin Nowak 2011-08-15 21:22:58 UTC
Can you please post the code.
Comment 3 Danny Arends 2011-08-16 01:02:02 UTC
Created attachment 1017 [details]
Segfault from fiber

The file I forgot to attach
Comment 4 Danny Arends 2011-08-16 01:02:30 UTC
Sorry forgot to attach the file.
Comment 5 Martin Nowak 2011-08-17 09:04:13 UTC
I can confirm this crash.
The reason though is not strictly a bug.
What you observe is a stack overflow due to big local buffers
in std.format.formatValue and even bigger ones in libc's vfprintf.
Fibers are allocated with a default stack size of one memory page (usually 4096 Bytes), but calling these two function already allocates >3KB stack space.

As a workaround you can increase the stack size in the Fiber constructor. I'm afraid there is no easy solution to determine the smallest possible stack size that is safe for all your code paths. In this example 8K => 'this() { super(&run, 8192); }' will suffice.

martin