Обзор
Примеры
Скриншоты
Сравнения
Приложения
Загрузить
Руководства
Базар
Статус и История
Частые вопросы (FAQ)
Авторы и лицензия
Форум
Помощь проекту
Поиск по сайту
Язык
русский













SourceForge.net Logo



Эта страница еще не переведена. Вы хотите перевести?

 

Thread synchronization primitives

 

 

Function List

 

void AssertST()

This operation can be used only DEBUG mode. If any Thread was started prior to calling AssertST, it will stop the execution with diagnostic message. The purpose is that some global initialization routines are best performed before any multi-threading starts. AssertST can be used to assure this as runtime check.

 


 

void ReadMemoryBarrier()

Read memory barrier. CPU and compiler is instructed not to do any loads ahead of ReadMemoryBarrier (which normally happens in out-of-order CPUs and can also be a result of compiler optimizations). See this or this for more detailed description of problem.

 


 

void WriteMemoryBarrier()

Write memory barrier. CPU and compiler is instructed not to do any writes ahead of WriteMemoryBarrier (which normally happens in out-of-order CPUs and can also be a result of compiler optimizations). See this or this for more detailed description of problem.

 


 

template <class U> U ReadWithBarrier(const volatile U& b)

This template reads the value of b (to temporary variable) and then invokes ReadMemoryBarrier. The value is returned. This assures that the value read is not affected by compiler or CPU load reorders. In other words, no read that is after the point of the function call can be performed before calling it.

 


 

template <class U, class V> void BarrierWrite(volatile U& dest, V data)

Invokes WriteMemoryBarier and then writes data.to dest. This assures that write is not affected by compiler or CPU reorders.  In other words, no write that is after the point of the function call can be performed before calling it.

 


 

typedef integer_type Atomic

This is the integer type that can be used as argument of AtomicXAdd function. It is compatible with 'int' - it has the same value range and it can be converted to 'int'.

 


 

int AtomicXAdd(volatile Atomic& t, int incr)

Adds incr to atomic variable t and returns the original value of t. The operation is atomic - it behaves as it would be serialized by Mutex, but is significantly cheaper in terms of CPU cycles and memory requirements (no Mutex really required...).

 


 

int AtomicInc(volatile Atomic& t)

Same as AtomicXAdd(t, +1) + 1.

 


 

int AtomicDec(volatile Atomic& t)

Same as AtomicXAdd(t, -1) - 1.

 


 

int AtomicRead(const volatile Atomic& t)

Same as ReadWithBarrier(t).

 


 

void AtomicWrite(volatile Atomic& t, int val)

Same as BarrierWrite(t, val).

 

 

Macro List

 

INTERLOCKED

This macro adds static Mutex to the block. For example:

        INTERLOCKED {

            Foo();

        }

    is equivalent to

        {    static StaticMutex uniquename;

            uniquename.Enter();

            Foo();

            uniquename.Leave();

        }

 


 

INTERLOCKED_(cs)

Similar to INTERLOCKED, but instead of 'anonymous' implicit static Mutex it uses explicit Mutex cs.

 


 

ONCELOCK

Designates block that only gets performed at first run, taking into account all multi-threading issues. In single threaded environment

        ONCELOCK { Foo(); }

    is equivalent to

        { static bool x; if(!x) { x = true; Foo(); } }.

 


 

ONCELOCK_(o_b_)

Similar to ONCELOCK, but using explicitly defined control variable.

 


 

ONCELOCK_PTR(ptr, init)

This special construction can be used to initialize a value of arbitrary pointer with expression. Initially, ptr is NULL, init should return a non-NULL value assignable to ptr. Value is initialized only once and only in that case init is evaluated. After that (when ptr is non-NULL) only ReadMemoryBarrier synchronization primitive is used to check the ptr, making the operation relatively fast.

 

 

Страница доступна на english языке. Вы хотите внести вклад?