Quantitative Analysis
Parallel Processing
Numerical Analysis
C++ Multithreading
Python for Excel
Python Utilities
Services
Author

I. Installation.
II. Threading primitives.
1. Encapsulation of primitives.
2. Preventing starvation.
3. Preventing race condition.
A. Guard primitives.
a. ReaderGuard.
b. WriterGuard.
c. UpgradeGuard.
d. TryGuard.
4. Barriers.
III. NonBlockingQueue.
IV. ThreadPool.
V. ThreadMaster.
VI. OTS Scheduler.
VII. Bibliography
Downloads. Index. Contents.

TryGuard.


he TryGuard is used to attempt to gain writer access. The constructor makes one attempt to write-lock the mutex. Afterwards the success of such attempt may be tested by accessing the "operator bool() const" of the TryGuard.

The following is the public interface.

class BadTryGuard: public boost::exception, public std::exception {};

template <class X, class Mutex>

class TryGuard

{

public:

explicit TryGuard( volatile X& x );

explicit TryGuard( volatile X* x );

TryGuard( volatile X& x, volatile const Mutex& mutex );

TryGuard( volatile X* x, volatile const Mutex& mutex );

~TryGuard();

operator bool() const;

Mutex& mutex() const;

X* ptr() const;

X* operator->();

X& operator*();

};

All constructors throw boost::thread_resource_error. The BadTryGuard is thrown when accessing the X while bool() is false.





Downloads. Index. Contents.


















Copyright 2007