Quantitative Analysis.
Trading Platform.
Python for Excel.
Author.
I.Installation.
II.OTS Scheduler.
1.Threading primitives.
A.Encapsulation of primitives.
B.Preventing starvation.
C.Preventing race condition.
a.Guard primitives.
i.ReaderGuard.
ii.WriterGuard.
iii.UpgradeGuard.
iv.TryGuard.
D.Barriers.
2.NonBlockingQueue.
3.ThreadPool.
4.ThreadMaster.
5.Scheduler implementation.
III.OTS Python Object Browser.
Bibliography.
Forum Index Contents Downloads

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.





Forum Index Contents Download


















Copyright 2009.