Re: task msging

new topic     » goto parent     » topic index » view thread      » older message » newer message
useless said...

After all, i can't tell which task called the msg handler unless it tells me truthfully who it is.

Actually, I think it can. Any time a task calls a routine, that routine is running as that task, and a call to task_self() should tell you what task called that routine. I don't know why i didn't think to say this before.

Try running this test to confirm it. Does this look correct to everyone? This proves that a subroutine doesn't need the task_id passed to it, it can get it with task_self().

Example:

 
include std/text.e 
 
puts(1, "Test to see if task_self() works in subroutines...\n") 
 
procedure print_task_id(atom id) 
    atom testid 
    testid = task_self() 
     
    puts(1, "id=" & sprint(id) & ", testid=" & sprint(testid)& "\n") 
end procedure 
 
procedure task_test() 
	for i = 1 to 10 do 
		print_task_id(task_self()) 
		task_yield() 
	end for 
	puts(1, "Press any key to continue...") 
	while 1 do 
        if get_key() then 
    		exit 
    	end if 
    	task_yield() 
	end while 
	abort(0) 
end procedure 
 
atom t1 = task_create(routine_id("task_test"), {}) 
atom t2 = task_create(routine_id("task_test"), {}) 
atom t3 = task_create(routine_id("task_test"), {}) 
atom t4 = task_create(routine_id("task_test"), {}) 
atom t5 = task_create(routine_id("task_test"), {}) 
atom t6 = task_create(routine_id("task_test"), {}) 
 
task_schedule(t1, {1, 1}) 
task_schedule(t2, {1, 1}) 
task_schedule(t3, {1, 1}) 
task_schedule(t4, {1, 1}) 
task_schedule(t5, {1, 1}) 
task_schedule(t6, {1, 1}) 
 
while 1 do 
    task_yield() 
end while 
 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu