View unanswered posts | View active topics It is currently Thu Nov 27, 2014 12:07 pm






Reply to topic  [ 2 posts ] 
Multitask and semaphore problem 
Author Message
Rookie
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?


Code:
   SemaphoreLock(_motorRW_,10);
   if(bDoesTaskOwnSemaphore(_motorRW_)){
      a = mSpeedA;
      b = mSpeedB;
      c = mSpeedC;
#ifdef DEBUGMOTOR
   writeDebugStreamLine("mGetRealMotion(): get lock");
#endif

      SemaphoreUnlock(_motorRW_);
   }


Sun Nov 11, 2012 12:52 am
Profile
Expert

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.

_________________
Matt


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.