# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

NLMISC::CUnfairSynchronized Class Template Reference

This class ensure that the Value is accessed by only one thread. More...

#include <mutex.h>

List of all members.

Public Methods

 CUnfairSynchronized (const std::string &name)

Private Attributes

volatile CUnfairMutex _Mutex
 The mutex of the synchronized value. More...

volatile T _Value
 The synchronized value. More...


Friends

class CUnfairSynchronized::CAccessor


Detailed Description

template<class T>
class NLMISC::CUnfairSynchronized< T >

This class ensure that the Value is accessed by only one thread.

First you have to create a CSynchronized class with you type. Then, if a thread want to modify or do anything on it, you create a CAccessor in a sub scope. You can modify the value of the CUnfairSynchronized using the value function until the end of the scope. So you have to put the smaller scope as you can.

Internally, this class uses a CUnfairMutex object (see CUnfairMutex for programming considerations).

 // the value that you want to be thread safe.
 CUnfairSynchronized<int> val;
 { // create a new scope for the access
   // get an access to the value
   CUnfairSynchronized<int>::CAccessor acces(&val);
   // now, you have a thread safe access until the end of the scope, so you can do whatever you want. for example, change the value
   acces.value () = 10;
 } // end of the access
 *
Author:
Vianney Lecroart , Nevrax France
Date:
2000

Definition at line 393 of file mutex.h.


Constructor & Destructor Documentation

template<class T>
NLMISC::CUnfairSynchronized< T >::CUnfairSynchronized const std::string &    name [inline]
 

Definition at line 397 of file mutex.h.

References _Mutex.


Friends And Related Function Documentation

template<class T>
friend class CUnfairSynchronized::CAccessor [friend]
 

Definition at line 429 of file mutex.h.


Member Data Documentation

template<class T>
volatile CUnfairMutex NLMISC::CUnfairSynchronized::_Mutex [private]
 

The mutex of the synchronized value.

Definition at line 432 of file mutex.h.

Referenced by CUnfairSynchronized.

template<class T>
volatile T NLMISC::CUnfairSynchronized::_Value [private]
 

The synchronized value.

Definition at line 435 of file mutex.h.


The documentation for this class was generated from the following file: