View Single Post
  #11   Spotlight this post!  
Unread 01-21-2009, 09:08 PM
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
Re: Semaphores and Synchronized's

slavik262, Thanks for the explanation, but i knew that from the C_CPP_Programming_Guide.pdf.
I did some more looking about, and I found the Answer:
Code:
//Top of file after includes
SEM_ID robotLock = semMCreate(SEM_Q_PRIORITY);//this creates a lock for the use of myRobot
//in a function somewhere else
		CRITICAL_REGION(robotLock);
		myRobot.Drive(1.0,0.0);
		END_REGION;
the robotLock variable is the lock that needs to be obtained for a safe procedure, but it is not neccesary. So someone could do this:
Code:
//Top of file after includes
SEM_ID robotLock = semMCreate(SEM_Q_PRIORITY);//this creates a lock for the use of myRobot
//in a function somewhere else
		CRITICAL_REGION(robotLock);
		myRobot.Drive(1.0,0.0);
		END_REGION;
//more code and other functions of a very complex nature here
myRobot.Drive(0.5,0.0);//this will compile but be not safe
So you need to explicitly obtain a lock for the variable you want and have decided to use for it.
Thanks for everyone's help in leading me to the right answer
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib
Reply With Quote