NXC: wait(1) for safe task (scheduling) control needed?
NXC: wait(1) for safe task (scheduling) control needed?
hi,
I'm currently extending my subsumption architecture program consisting of up to 20 tasks.
Do I need to insert a
Wait(1)
into each task for a safe task (scheduling) control?
I'm actually curious because if I needed to, I'm afraid of waisting 20*1ms for each time slice scheduling round - (sorry don't know the exact English term)
I'm currently extending my subsumption architecture program consisting of up to 20 tasks.
Do I need to insert a
Wait(1)
into each task for a safe task (scheduling) control?
I'm actually curious because if I needed to, I'm afraid of waisting 20*1ms for each time slice scheduling round - (sorry don't know the exact English term)
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: NXC: wait(1) for safe task (scheduling) control needed?
I don't really fully understand the question, but I don't think you need to use wait functions so that the NXT doesn't have errors when multitasking. I think that the NXT takes care of making sure that the multitasking resources are used properly. If you are using mutexes, I think wait functions can be used to sort of set priority.
Also, can 20 tasks be running at the same time? That seems like a lot to me. I think I may have heard that 5 is the limit (at one time).
Also, can 20 tasks be running at the same time? That seems like a lot to me. I think I may have heard that 5 is the limit (at one time).
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: NXC: wait(1) for safe task (scheduling) control needed?
Although 20 tasks is a bit insane... I think you could do it, but I don't know for sure. Just be sure not to go over the firmware's really dumb limit of 256 tasks+function declarations. Maybe this should be a wish for the NBC/NXC Enhanced Firmware - enable more than 256 tasks/functions to be declared.
To answer the OP's question: no, you're not wasting time. The VM will do what it should automatically do - switch to a new task. Just be sure that your waits aren't excessive - Wait(10000) for every task would just freeze your program. If you're worried about wasting a few nanoseconds, you could use Yield().
John also once wrote a very nice post on how to use #pragma task_priority 20 or something. I can't remember anything... I think it was lost with the downfall of NXTasy. Could you explain it again? Please? (See? I even went to the trouble of finding the right smiley for the job! )
To answer the OP's question: no, you're not wasting time. The VM will do what it should automatically do - switch to a new task. Just be sure that your waits aren't excessive - Wait(10000) for every task would just freeze your program. If you're worried about wasting a few nanoseconds, you could use Yield().
John also once wrote a very nice post on how to use #pragma task_priority 20 or something. I can't remember anything... I think it was lost with the downfall of NXTasy. Could you explain it again? Please? (See? I even went to the trouble of finding the right smiley for the job! )
Last edited by muntoo on 26 Feb 2011, 04:44, edited 2 times in total.
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: NXC: wait(1) for safe task (scheduling) control needed?
Now how, may I ask, did you learn of the limit? I certainly didn't know that, thanks for that oh-so important piece of information
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: NXC: wait(1) for safe task (scheduling) control needed?
I knew it from before, but here it is in the NXC Guide:mattallen37 wrote:Now how, may I ask, did you learn of the limit? I certainly didn't know that, thanks for that oh-so important piece of information
NXC Guide wrote: There are two distinct types of code blocks: tasks and functions. Each type of code block has its own unique features, but they share a common structure. The maximum number of code blocks of both tasks and functions combined is 256.
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
-
- Posts: 73
- Joined: 29 Sep 2010, 12:05
Re: NXC: wait(1) for safe task (scheduling) control needed?
I suggest using Yield() rather than Wait(1).
Regards, Morton
Re: NXC: wait(1) for safe task (scheduling) control needed?
This is from the API dump:
They're one and the same
- Xander
Code: Select all
/**
* Yield to another task.
* Make a task yield to another concurrently running task.
*/
inline void Yield() { asm { wait 1 } }
- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
-
- Posts: 73
- Joined: 29 Sep 2010, 12:05
Re: NXC: wait(1) for safe task (scheduling) control needed?
Exactly. But 'Yield()' is easier to type and reads better.mightor wrote:They're one and the same
Regards, Morton
Re: NXC: wait(1) for safe task (scheduling) control needed?
thanks guys for your replies, but I didn't manage to find the answer to my TO question - so again, maybe it was not clearly enough:
- I need to have up to 20 tasks, and this amount of tasks I won't change (currently it's 14, but the limit of independent behaviours has not been finally reached, and admittedly not all of them have to run as quick as possible; for the low priority tasks I'm currently using a Wait(20) or a Wait(50).
- but for the very quick calculating tasks (Neural Net, Navigator, BT Sensor-And-Motor-Multiplexer, Speech Recognition) I actually don't want a Wait(1) if avoidable - but nevertheless there must be enough cpu time remaining for the rest.
So again my question:
MUST I FOR SURE insert at least a Wait(1) to ALL task loops (also to the very fast ones) for a safe scheduling or not ?
- I need to have up to 20 tasks, and this amount of tasks I won't change (currently it's 14, but the limit of independent behaviours has not been finally reached, and admittedly not all of them have to run as quick as possible; for the low priority tasks I'm currently using a Wait(20) or a Wait(50).
- but for the very quick calculating tasks (Neural Net, Navigator, BT Sensor-And-Motor-Multiplexer, Speech Recognition) I actually don't want a Wait(1) if avoidable - but nevertheless there must be enough cpu time remaining for the rest.
So again my question:
MUST I FOR SURE insert at least a Wait(1) to ALL task loops (also to the very fast ones) for a safe scheduling or not ?
Re: NXC: wait(1) for safe task (scheduling) control needed?
No, it is not necessary since it's pre-emptive, however, it is better to insert a wait where you know you're going to wait for something anyway.
- Xander
- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
Who is online
Users browsing this forum: No registered users and 1 guest