View unanswered posts | View active topics It is currently Sat Jun 23, 2018 12:43 am

Reply to topic  [ 2 posts ] 
Multitask and semaphore problem 
Author Message
User avatar

Joined: Sun Jun 17, 2012 11:18 am
Posts: 26
Post Multitask and semaphore problem
Hi all,

I'm doing a robot project. In the program, I have two tasks who need to access the same set of variables. To secure synchronization, I use a semaphore to protect the critical section as below code. However, when the two tasks are executing concurrently, it appears one of them always defeats another and "hogs" the semaphore, instead of the expected time-sharing behavior. The two tasks should have the same default priority that I haven't specified. Do you suggest any cause?

      a = mSpeedA;
      b = mSpeedB;
      c = mSpeedC;
   writeDebugStreamLine("mGetRealMotion(): get lock");


Sun Nov 11, 2012 12:52 am

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Post Re: Multitask and semaphore problem
The NXT processor is physically only able to do one thing at a time. The FW provides a VM which supports multiple tasks, but still only one can be run at a time (it's probably round-robin). With the NXC/NBC Enhanced Lego FW, the VM executes twenty OP-Codes before moving on (unless the program specifies to move on sooner, using Wait or Yield), and I would assume that the ROBOTC FW VM functions similarly.

Basically that means that it is impossible to make two tasks run at the same time. If you need it to be as close as possible, I suggest combining the two tasks into one, which would give you as the programmer ultimate execution order control, and also reduce VM overhead.


Mon Nov 12, 2012 12:57 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.