WPILib 2012
WPILibRoboticsLibraryforFRC
Public Member Functions
Synchronized Class Reference

#include <Synchronized.h>

List of all members.

Public Member Functions

 Synchronized (SEM_ID)
virtual ~Synchronized ()

Detailed Description

Provide easy support for critical regions. A critical region is an area of code that is always executed under mutual exclusion. Only one task can be executing this code at any time. The idea is that code that manipulates data that is shared between two or more tasks has to be prevented from executing at the same time otherwise a race condition is possible when both tasks try to update the data. Typically semaphores are used to ensure only single task access to the data. Synchronized objects are a simple wrapper around semaphores to help ensure that semaphores are always signaled (semGive) after a wait (semTake).


Constructor & Destructor Documentation

Synchronized::Synchronized ( SEM_ID  semaphore) [explicit]

Synchronized class deals with critical regions. Declare a Synchronized object at the beginning of a block. That will take the semaphore. When the code exits from the block it will call the destructor which will give the semaphore. This ensures that no matter how the block is exited, the semaphore will always be released. Use the CRITICAL_REGION(SEM_ID) and END_REGION macros to make the code look cleaner (see header file)

Parameters:
semaphoreThe semaphore controlling this critical region.
Synchronized::~Synchronized ( ) [virtual]

Syncronized destructor. This destructor frees the semaphore ensuring that the resource is freed for the block containing the Synchronized object.


The documentation for this class was generated from the following files:
 All Classes Functions Variables