Starting and stopping threads programmatically

Technical questions regarding the XTC tools and programming with XMOS.
Matt
Active Member
Posts: 50
Joined: Sat Feb 13, 2010 12:04 pm

Starting and stopping threads programmatically

Post by Matt »

Hi,

I am sure I have seen an answer to this question before but can not find it for the life of me.

Is it possible to start and stop threads programmatically using C or XC.
I would like to be able to kill a task/thread at will and restart it when needed.

Cheers

Matt


User avatar
Andy
Respected Member
Posts: 279
Joined: Fri Dec 11, 2009 1:34 pm

Post by Andy »

I think this is thread you're thinking of...

http://xcore.com/forum/viewtopic.php?f=10&t=420
Matt
Active Member
Posts: 50
Joined: Sat Feb 13, 2010 12:04 pm

Post by Matt »

I did see this one but I was hoping for a simpler answer. ThreadStop(core,thread); etc
User avatar
monk_is_batman
Active Member
Posts: 38
Joined: Wed Jun 09, 2010 3:20 am
Location: Maine, USA

Post by monk_is_batman »

The reason this is not a simple task is because of XC. The way XC handles parallel threads is to always make them be synchronized, because of this you cannot just stop one of the threads or it causes problems.

The hardware is completely capable of it and I have even succeeded with it in some circumstances. However due to the restriction built into XC the only real way to achieve the starting/stopping of threads you are looking for is to use a bunch of assembly, possibly inter-weaved through your C/XC code.
User avatar
Woody
XCore Addict
Posts: 165
Joined: Wed Feb 10, 2010 2:32 pm

Post by Woody »

monk_is_batman wrote:The hardware is completely capable of it and I have even succeeded with it in some circumstances.
I'm not sure I'd fully agree with you there. The hardware is capable of freeing arbitrary threads using the FREER instruction (i.e. stopping them), but restarting them from where they left off is a different matter. So long as the threads to be stopped were saving configuration information regularly to memory (or down a channel) then theoretically the threads could be restarted from known points.

The safest way to implement this is for the threads to be paused to regularly check for a stop command down a channel, then pause waiting for a subsequent start instruction. The pausing thread will obviously not respond immediately, but XTA could be used to determine the maximum pause latency.
User avatar
monk_is_batman
Active Member
Posts: 38
Joined: Wed Jun 09, 2010 3:20 am
Location: Maine, USA

Post by monk_is_batman »

The hardware is capable of freeing arbitrary threads using the FREER instruction (i.e. stopping them), but restarting them from where they left off is a different matter.
I agree with you completely, its possible I misread the question. I was thinking that if a process/task was killed it would stop its operation and if it was restarted it would start from the beginning. Continuing from the stop point would be a tricky thing to master, makes me interested.
User avatar
dave
Member++
Posts: 31
Joined: Thu Dec 10, 2009 10:11 pm

Post by dave »

You should be able do this with a channel and an interrupt handler.

A message sent on the channel will then cause an interrupt, pausing the
thread immediately.

The interrupt handler can take this message (probably
just an EOM), input another EOM and return from interrupt. So to restart
you just send another message.