ASL
Atomic< T > Class Template Reference

Detailed Description

template<class T>
class asl::Atomic< T >

Atomic version of another type.

This adds some space and overhead, use with care.

Atomic<double> value = 0;
value += 1.5;

Variable value can be read or written from different threads without interfering.

Basic operators of the underlying type are exposed (++, +=, -=, *=, /=, ==, <<, ...). If the underlying type is a class you can call methods using opertor ->, and those calls will be syncronized.

Atomic<Array<float>> numbers;
numbers->sort(); // this is atomic

For other operations you can cast to the underlying type or use operator ~. Or you can use operator * to get a reference to the internal variable (with no synchronization). In that case you can use the objet's mutex to protect access:

int appendAtomic(Atomic<Array<int>>& list, double number)
{
Lock _(list);
(*list) << number; // can't use operator -> when explicitly locked!
return (*list).length();
}

#include <Mutex.h>

Public Member Functions

T & operator* ()
 Returns a reference to the internal value (not synchronized)
 
Mutexmutex ()
 Returns the internal mutex for synchronization.
 
operator~ () const
 Returns the value of this variable as a copy.
 
 operator T () const
 Returns the value of this variable as a copy.
 
Locked< T > locked ()
 Returns a locked wrapper for short time use.
 
Locked< T > operator-> ()
 Allows calling member functions of the internal object.
 

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