Hi David,

Someone forwarded me a copy of my email, and this was my response to him:

That fix is correct, but it brings up a point about why stop wasn't
even stopping the thread.  I looked through the code, and the issue is
that stop() only works correctly if it is called by a thread that is
NOT the current thread.  Semantically, calling suspend() / wakeup() is
correct for what pause() and resume() are supposed to do, so the fix
is correct, but the problem with stop() still needs to be addressed.
Should be as simple as changing around the logic in the
ThreadScheduler.stopThread() function to properly consider the case of
TOSTHREAD_STATE_ACTIVE.

I think Mike Liang is going to commit a patch in the next few days.
Originally I wrote stop() to only work when called from another thread
because it seemed logical to me that the thread should just return,
rather than calling stop() directly, but I can see cases where it
makes sense to call stop if you are deep inside some call chain and
you just want to kill yourself immediately.

Kevin

On Tue, Jan 18, 2011 at 8:44 PM, David Rodda <[email protected]> wrote:
> Hi
>
> I am using the latest TInyos 2.x from Subersion, on a Shimmer (MSP430) mote.
>
> I am experiencing unexpected behaviour using the Thread.pause() and 
> Thread,resume() functions when using TosThreads.
> My understanding is that when Thread.pause() is called from within a thread 
> it should sleep, until another thread or event calls Thread.resume().  
> However, I am finding that while Thread.pause() returns SUCCESS, the thread 
> continues executing.
>
> When using condition a variable the thread waiting on the condition variable 
> sleeps until the condition variable is signalled.
>
> I notice in tinyos-2.x/tos/lib/tosthreads/system/StaticThreadP.nc, which 
> provides the Thread interface, Thread.pause() calls 
> ThreadScheduler.stopThread(), whereas I would have expected it to call 
> ThreadScheduler.suspendCurrentThread() as is the case with the condition 
> variable implementation.  Using the patch below makes Thread.pause() and 
> Thread.resume() function as expected.
>
> Have I misinterpreted the way pause and resume should function? Does this fix 
> make sense?
>
> Thanks
> David
>
> ----------------------------------------------------------------------------------------------------------
> Index: StaticThreadP.nc
> ===================================================================
> --- StaticThreadP.nc    (revision 5307)
> +++ StaticThreadP.nc    (working copy)
> @@ -73,11 +73,11 @@
>   }
>
>   command error_t Thread.pause[uint8_t id]() {
> -    return call ThreadScheduler.stopThread(id);
> +    return call ThreadScheduler.suspendCurrentThread();
>   }
>
>   command error_t Thread.resume[uint8_t id]() {
> -    return call ThreadScheduler.startThread(id);
> +    return call ThreadScheduler.wakeupThread(id);
>   }
>
>   command error_t Thread.stop[uint8_t id]() {
>
> ---------------------------------------- End Diff 
> ------------------------------------------------------
>
> The information in this e-mail may be confidential and subject to legal 
> professional privilege and/or copyright. National ICT Australia Limited 
> accepts no liability for any damage caused by this email or its attachments.
>
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>



-- 
~Kevin

_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to