NXC: wait(1) for safe task (scheduling) control needed?

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

NXC: wait(1) for safe task (scheduling) control needed?

Post by HaWe »

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)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC: wait(1) for safe task (scheduling) control needed?

Post by mattallen37 »

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).
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC: wait(1) for safe task (scheduling) control needed?

Post by muntoo »

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? Image (See? I even went to the trouble of finding the right smiley for the job! ImageImageImage)
Last edited by muntoo on 26 Feb 2011, 04:44, edited 2 times in total.
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC: wait(1) for safe task (scheduling) control needed?

Post by mattallen37 »

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 :lol:
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC: wait(1) for safe task (scheduling) control needed?

Post by muntoo »

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 :lol:
I knew it from before, but here it is in the NXC Guide:
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.
Doc, does this count as b******izing the quotes? ;)
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
m-goldberg
Posts: 73
Joined: 29 Sep 2010, 12:05

Re: NXC: wait(1) for safe task (scheduling) control needed?

Post by m-goldberg »

I suggest using Yield() rather than Wait(1).
Regards, Morton
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: NXC: wait(1) for safe task (scheduling) control needed?

Post by mightor »

This is from the API dump:

Code: Select all

/**
 * Yield to another task.
 * Make a task yield to another concurrently running task.
 */
inline void Yield() { asm { wait 1 } }
They're one and the same :)

- 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)
m-goldberg
Posts: 73
Joined: 29 Sep 2010, 12:05

Re: NXC: wait(1) for safe task (scheduling) control needed?

Post by m-goldberg »

mightor wrote:They're one and the same :)
Exactly. But 'Yield()' is easier to type and reads better.
Regards, Morton
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: wait(1) for safe task (scheduling) control needed?

Post by HaWe »

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 ?
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: NXC: wait(1) for safe task (scheduling) control needed?

Post by mightor »

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
| 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)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest