示例#1
0
void begin() {
  initFibers();

  CTR_FIBER_CONTROLLER = ctr_internal_create_object(CTR_OBJECT_TYPE_OTEX);
  ctr_internal_create_func(CTR_FIBER_CONTROLLER, ctr_build_string_from_cstring("toString"), &ctr_fiber_tostring);
  ctr_internal_create_func(CTR_FIBER_CONTROLLER, ctr_build_string_from_cstring("new:"), &ctr_fiber_spawn);
  ctr_internal_create_func(CTR_FIBER_CONTROLLER, ctr_build_string_from_cstring("yield:"), &ctr_fiber_yield); //with value
  ctr_internal_create_func(CTR_FIBER_CONTROLLER, ctr_build_string_from_cstring("yield"), &ctr_fiber_yield); //without value
  ctr_internal_create_func(CTR_FIBER_CONTROLLER, ctr_build_string_from_cstring("yielded"), &ctr_fiber_yielded);
  ctr_internal_create_func(CTR_FIBER_CONTROLLER, ctr_build_string_from_cstring("waitForAll"), &ctr_fiber_join_all);
  ctr_internal_object_add_property(CTR_FIBER_CONTROLLER, ctr_build_string_from_cstring("fiberId"), ctr_build_number_from_float(-1), CTR_CATEGORY_PRIVATE_PROPERTY);

  ctr_internal_object_add_property(CtrStdWorld, ctr_build_string_from_cstring("Fiber"), CTR_FIBER_CONTROLLER, 0);
}
示例#2
0
int main()
{
	/* Initialize the fiber library */
	initFibers();
	
	/* Go fibers! */
	spawnFiber( &fiber1 );
	spawnFiber( &fibonacchi );
	spawnFiber( &squares );

	/* Since these are nonpre-emptive, we must allow them to run */
	waitForAllFibers();
	
	/* The program quits */
	return 0;
}