Component index
Section index

Component COROUTINE


Search

	/*
	    The switch between the parent and the coroutine (in the run functag)
	    is rather fast. On a 2Ghz P4 (thinkpad), this sample runs in
	    0.15 seconds.
	*/
	<mod>
	static void sample_coroutine2()
	{
	    printf ("Starting\n");
	    long long now = getnow();
	    glocal int loop=0;
	    <obj COROUTINE co>();
	    <f run>
	        for (int i=0; i<1000000; i++){
	            glocal.loop++;
	            yield();
	        }
	    </f>
	    </obj>
	    while (co.next());
	    long long end = getnow();
	    long long diff = end - now;
	    printf ("%d loop in %ld.%06ld seconds\n",glocal.loop
	        ,(long)(diff/1000000),(long)(diff%1000000));
	}
	</mod>