ASL
Loading...
Searching...
No Matches
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;
An Array is a contiguous and resizable array of any type of elements.
Definition Array.h:69

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.

numbers->sort(); // this is atomic
Array & sort()
Sorts the array using the elements' < operator "in place".
Definition Array.h:505

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:

{
Lock _(list);
(*list) << number; // can't use operator -> when explicitly locked!
return (*list).length();
}
int length() const
Returns the number of elements in the array.
Definition Array.h:171
Atomic version of another type.
Definition Mutex.h:446
A Lock is an automatic locker/unlocker of a Mutex.
Definition Mutex.h:395

#include <Mutex.h>

Public Member Functions

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

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