Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Threading and Synchronization

Detailed Description

There are only four required base synchronization objects currently needed to support the thread safety and robustness of the Phission system. All thread safe objects will inherit from the phMutex class and generally locks the object whenever a method is invoked. Any object requiring synchronization in a producer / consumer model can use the phSemaphore class. One instance is the phLiveObject that allocates a phSemaphore for each attached listening object/thread and posts a semaphore when the phLiveObject::nofity method has been called. The phLiveObject::notify method is used when the inheriting object has changed some internal data component and is signaling that change to listening objects. The phLiveObject also wraps the Reader-Writer lock to allow multiple readers of data within the inheriting classes of the phDataObject. The phImage object is one instance of an inheriting object and any added data object classes such as a the planned phAudio class. The phBlobData and phHistogramData objects also inherit from the phLiveObject to provide asynchronous updating of filter output objects. phCondition is used internally within the phThread class to provide synchronized startup of threads and allow signaling of errors during startup. There is no asynchronous mechanism available to start up a phThread currently since it's not necessary and could lead to more complicated issues.

[ Email questions or comments ] [ Join the mailing list ]


class  phCondition
 This class implements a platform independent condition variable mechanism. Not every platform has it's own implementation and other algorithms were found to create condition variables where they aren't natively supported. These algorithms use a combination of mutexes and semaphores to emulate the behavior of condition variables. While it might seem straight forward to use the algorithms, it required a bit of work. The implemented algorithm using Win32 API and using the Phission API for the Blackfin was derived from: More...
class  phConditionCounter
 This is a Condition Counter class that allows for threads to block while waiting for a specific value setting. Threads will call phConditionCounter::waitForValue with a value parameter and a conditional operation choice to compare the passed value with the counter value. In order to provide the condition variable functionality, this class inherits from the phCondition class. The phConditionCounter::waitForValue method is a convenience because it simplifies the code at higher levels when a specific value is desired where hard looping or sleeping will impact performance. The waiting doesn't return until the condition is met whereas phConditon will return whenever the condition is signaled. More...
class  phMutex
 phMutex provides platform independent locking mechanisms to the Phission code. The phMutex is a recursive implemented mutex. Multiple mutexes can be obtained by a thread by calling the phMutex::lock() method and each successful phMutex::lock() should be matched with a call to the phMutex::unlock() method. If there isn't one phMutex::unlock() call for every phMutex::lock()/phMutextryLock() call that succeeded, deadlock could occur in other threads that are trying to obtain the lock. Recursive mutexes are necessary for a system such as Phission where a call to the current object's method may also call other methods that belong to the same instance of the object. Those other methods could be called on their own as well. Without recursive mutexes, the one scope calling into another scope (scope being separate methods or blocks of code) will deadlock on the second attempt at locking. More...
class  phRWLock
 This class provides a platform independent Reader-Writer class. More...
class  phSemaphore
 This class implements a thread safe portable semaphore class. It extend the normal interface of a semaphore with the phSemaphore::postWaiting and phSemaphore::postMax methods. This semaphore object will keep track of the number of waiting threads at any instance in time to allow them to all be 'woken up' if necessary to permit the proper shutdown or cleanup of a thread or series of threads. Being able to post the maximum number of semaphores possible without any of the threads returning until all the semaphores are posted can be useful in synchronization. Otherwise, the semaphores can be posted one at a time. More...
class  phThread
 C++ wrapper class for threading. More...


#define phCondition_RECEIVED   phSUCCESS
#define phCondition_NOTRECEIVED   1
#define phCHECK_NOT_EQUAL   (1<<0)
#define phCHECK_EQUAL   (1<<1)
#define phCHECK_GREATER_THAN   (1<<2)
#define phCHECK_LESS_THAN   (1<<3)
#define phCHECK_E   phCHECK_EQUAL
#define phConditionCounter_WAKEUP   (-2)
#define phTHIS_LOOSE_LOCK(l)
#define phTHIS_LOCK(l)
#define phTHIS_TRYLOCK(l, gotlock)
#define phTHIS_LOOSE_TRYLOCK(l, gotlock)
#define phTHIS_LOOSE_UNLOCK(l)
#define phTHIS_UNLOCK(l)
#define phTHIS_ERROR_UNLOCK(l)
#define phTHIS_UNLOCK_RET(l, success_value, error_value)
#define phMUTEX_LOCK(m, l)
#define phMUTEX_TRYLOCK(m, l, gotlock)
#define phMUTEX_LOOSE_TRYLOCK(m, l, gotlock)
#define phMUTEX_LOOSE_LOCK(m, l)
#define phMUTEX_UNLOCK(m, l)
#define phMUTEX_LOOSE_UNLOCK(m, l)
#define phMUTEX_ERROR_UNLOCK(m, l)
#define phMUTEX_UNLOCK_RET(m, l, success_value, error_value)
#define phRWLOCK_READLOCK(rw, l)
#define phRWLOCK_READLOCK_LOOSE(rw, l)
#define phRWLOCK_WRITELOCK(rw, l)
#define phRWLOCK_UNLOCK(rw, l)
#define phRWLOCK_UNLOCK_LOOSE(rw, l)
#define phRWLOCK_UNLOCK_ERROR(rw, l)
#define phRWLock_OWNED   1
#define phRWLock_NOTLOCKED   1
#define phSemaphoreNOFLAG   (0)
#define phSemaphoreNOWAIT   (1<<0)
#define phSemaphoreWAIT   (1<<1)
#define phSemNOFLAG   phSemaphoreNOFLAG
#define phSemNOWAIT   phSemaphoreNOWAIT
#define phSemWAIT   phSemaphoreWAIT
#define phSemaphoreNOTAKE   1
#define phSemaphoreTAKEN   phSUCCESS
#define SEM_VALUE_MAX   2147483647
#define phNOFLAG   0
#define phDETACHED   (1<<1)


typedef ph_condition_info_tph_condition_info
typedef ph_mutex_info_tph_mutex_info
typedef ph_rwlock_info_tph_rwlock_info
typedef ph_semaphore_info_tph_semaphore_info
typedef ph_thread_info_tph_thread_info

Copyright (C) 2002 - 2007 Philip D.S. Thoren ( )
University Of Massachusetts at Lowell
Robotics Lab Logo

Generated on Sat Jun 16 02:45:27 2007 for phission by  doxygen 1.4.4