ari@columbia.edu (Ari Gross) (11/24/89)
There seems to be a problem with the printf command when using the lightweight process library. Here is an example taken from the SUN tutorial document on lightweight processes (Ch 6, pgs 75-76) that is supposed to give an example of how threads can be used to run coroutines. If the string constants in the example are replaced with integer variables, the code compiles and runs properly, as in the tutorial example. If the constants are changed to floats however, as below, the program hangs. It looks like there is a problem with the print command when used with threads. Any suggestions ??? [BTW, I am running this on a SUN 3.] Ari Gross ari@cs.columbia.edu /* buggy coroutine code using threads */ #include <lwp/lwp.h> #include <lwp/stackdep.h> thread_t co1; thread_t co2; thread_t co3; main() { float num1; int coroutine(), other(); lwp_self(&co1); lwp_setstkcache(1000,3); lwp_create(&co2, coroutine, MINPRIO, 0, lwp_newstk(), 0); lwp_create(&co3, other, MINPRIO, 0, lwp_newstk(), 0); num1 = 1.0; printf("%f\n",num1); lwp_yield(THREADNULL); num1 = 4.0; printf("%f\n",num1); lwp_yield(co3); num1 = 6.0; printf("%f\n",num1); exit(0); } coroutine() { float num2; num2 = 2.0; printf("%f\n",num2); if (lwp_yield(THREADNULL) < 0) { lwp_perror("bad yield"); return; } num2 = 7.0; printf("%f\n",num2); } other() { float num3; num3 = 3.0; printf("%f\n",num3); lwp_yield(THREADNULL); num3 = 5.0; printf("%f\n",num3); } /* end code */