1. Multitasking - need help
- Posted by X_Files Mar 21, 2012
- 1488 views
Hi. I'm trying to learn multitasking in Euphoria. I have 2 questions:
Here is my example (from manual):
include std\os.e atom t1_running = 0 procedure task1() for i = 1 to 10 do printf( 1, " Task (%2d) - sec: %7.4f\n", { i, time() } ) task_yield() end for t1_running = 0 end procedure atom t1 = task_create( routine_id( "task1" ), "" ) task_schedule( t1, 3 ) t1_running = 1 while t1_running = 1 do sleep( 4 ) printf( 1, "MAIN PROG - sec: %7.4f\n", { time() } ) task_yield() end whileOutput is:
MAIN PROG - sec: 4.2340 Task ( 1) - sec: 4.2340 MAIN PROG - sec: 8.2340 Task ( 2) - sec: 8.2340 Task ( 3) - sec: 8.2340 Task ( 4) - sec: 8.2340 MAIN PROG - sec: 12.2340 Task ( 5) - sec: 12.2340 Task ( 6) - sec: 12.2340 Task ( 7) - sec: 12.2340 MAIN PROG - sec: 16.2340 Task ( 8) - sec: 16.2340 Task ( 9) - sec: 16.2340 Task (10) - sec: 16.2340 MAIN PROG - sec: 20.2340
1. First time task is executed once. Why?
2. Same example, but I change task scheduler to task_schedule( t1, { 3, 3.2 } ) Output is:
MAIN PROG - sec: 4.2500 Task ( 1) - sec: 4.2500 MAIN PROG - sec: 8.2500 Task ( 2) - sec: 8.2500 MAIN PROG - sec: 12.2500 Task ( 3) - sec: 12.2500 MAIN PROG - sec: 16.2500 Task ( 4) - sec: 16.2500 MAIN PROG - sec: 20.2650 Task ( 5) - sec: 20.2650 MAIN PROG - sec: 24.2650 Task ( 6) - sec: 24.2650 MAIN PROG - sec: 28.2650 Task ( 7) - sec: 28.2650 MAIN PROG - sec: 32.2650 Task ( 8) - sec: 32.2650 MAIN PROG - sec: 36.2650 Task ( 9) - sec: 36.2650 MAIN PROG - sec: 40.2650 Task (10) - sec: 40.2650 MAIN PROG - sec: 44.2650I see that task is executed always when time (first parameter in sequence) passes and is not depend on second parameter. What is second parameter?
2. Re: Multitasking - need help
- Posted by gbonvehi Mar 24, 2012
- 1286 views
Hi X_Files,
I've never used euphoria's multitask so I can't be of much help here. However, I can help you by linking to task_schedule's definition: http://openeuphoria.org/docs/std_task.html#_1896_task_schedule
There you'll find what the parameter means when it's a sequence.
Cheers, Guillermo