libProcTer::CCriticalSection Class Reference

#include <cthread.h>

Inheritance diagram for libProcTer::CCriticalSection:

libProcTer::CCriticalVector< T > libProcTer::CTexture

List of all members.

Public Member Functions

 CCriticalSection ()
 Constructor.
 ~CCriticalSection ()
 Destructor.
void lock ()
void unlock ()


Detailed Description

Author:
CJP <cornware-cjp@users.sourceforge.net>
A critical section is needed to organize access behavior when different threads in a multithreaded application need to have access to the same objects.

As an example, suppose you have a linked list that is used by two threads simultaneously. Suppose one thread is busy adding an element to the list. This involves some administration in setting the pointers right. While it is in the middle of doing this, a second thread starts reading in the list. As the adding is only half-finished, some pointers may point to non-allocated memory. This may lead to a crash of the second thread.

To avoid this kind of trouble, you need to make sure only one thread at a time has access to an object. This is where CCriticalSection comes to help you.

A CCriticalSection can be locked by a thread. As long as it is locked, other threads can not lock it. So, when threads follow the following procedure, this ensures thread-safety:

Always make sure you call unlock(). Never call lock() twice without an unlock() inbetween. If you fail to follow these rules, you might find yourself in a "deadlock" situation, where your thread (and other threads) are waiting for the lock to be released, while no thread will ever release it.

There is more to say about this topic; you'll probably find plenty of reading material on multithreaded programming on the internet.


Constructor & Destructor Documentation

libProcTer::CCriticalSection::CCriticalSection (  ) 

Constructor.

libProcTer::CCriticalSection::~CCriticalSection (  ) 

Destructor.


Member Function Documentation

void libProcTer::CCriticalSection::lock (  ) 

Locks the critical section. If it is already locked, this method will block until the critical section is unlocked.

Reimplemented in libProcTer::CTexture.

void libProcTer::CCriticalSection::unlock (  ) 

Unlocks the critical section.

Reimplemented in libProcTer::CTexture.


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

Generated on Sun Aug 2 13:23:11 2009 for libprocter by  doxygen 1.5.8