www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - trouble compiling Fiber example code from docs dmd linux v2.067.1

reply "Carl Sturtivant" <sturtivant gmail.com> writes:
I took the example code from here,
http://dlang.org/phobos/core_thread.html#.Fiber
and wrapped the statements at the bottom inside main() and put 
import core.thread and std.stdio at the top, and the compiler 
gave me the following.

/usr/include/dmd/druntime/import/core/thread.d(3894): Error: 
static variable PAGESIZE cannot be read at compile time
fiberexample.d(8):        called from here: super.this(&this.run, 
PAGESIZE * 4LU)
/usr/include/dmd/druntime/import/core/thread.d(3871): Error: 
static variable PAGESIZE cannot be read at compile time

Help anyone?
Aug 06 2015
parent "anonymous" <anonymous example.com> writes:
On Thursday, 6 August 2015 at 20:21:38 UTC, Carl Sturtivant wrote:
 I took the example code from here,
 http://dlang.org/phobos/core_thread.html#.Fiber
 and wrapped the statements at the bottom inside main() and put 
 import core.thread and std.stdio at the top, and the compiler 
 gave me the following.

 /usr/include/dmd/druntime/import/core/thread.d(3894): Error: 
 static variable PAGESIZE cannot be read at compile time
 fiberexample.d(8):        called from here: 
 super.this(&this.run, PAGESIZE * 4LU)
 /usr/include/dmd/druntime/import/core/thread.d(3871): Error: 
 static variable PAGESIZE cannot be read at compile time

 Help anyone?
This isn't really clear from the example, but you need to put the bottom part in a function (e.g. main), including the variable initializations. I.e.: ---- void main() { // create instances of each type Fiber derived = new DerivedFiber(); Fiber composed = new Fiber( &fiberFunc ); // call both fibers once derived.call(); composed.call(); printf( "Execution returned to calling context.\n" ); composed.call(); // since each fiber has run to completion, each should have state TERM assert( derived.state == Fiber.State.TERM ); assert( composed.state == Fiber.State.TERM ); } ----
Aug 06 2015