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
Starting and stopping threads programmatically
-
- Active Member
- Posts: 50
- Joined: Sat Feb 13, 2010 12:04 pm
-
- Respected Member
- Posts: 279
- Joined: Fri Dec 11, 2009 1:34 pm
-
- Active Member
- Posts: 50
- Joined: Sat Feb 13, 2010 12:04 pm
I did see this one but I was hoping for a simpler answer. ThreadStop(core,thread); etc
-
- Active Member
- Posts: 38
- Joined: Wed Jun 09, 2010 3:20 am
- Location: Maine, USA
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.
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.
-
- XCore Addict
- Posts: 165
- Joined: Wed Feb 10, 2010 2:32 pm
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.monk_is_batman wrote:The hardware is completely capable of it and I have even succeeded with it in some circumstances.
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.
-
- Active Member
- Posts: 38
- Joined: Wed Jun 09, 2010 3:20 am
- Location: Maine, USA
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.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.
-
- Member++
- Posts: 31
- Joined: Thu Dec 10, 2009 10:11 pm
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.
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.