DotMP
Public Member Functions | Static Public Member Functions | Static Protected Attributes | Properties | Private Attributes | List of all members
DotMP.Shared< T > Class Template Reference

A shared variable that can be used in a parallel region. This allows for a variable to be declared inside of a parallel region that is shared among all threads, which has some nice use cases. More...

Inheritance diagram for DotMP.Shared< T >:
Inheritance graph
[legend]
Collaboration diagram for DotMP.Shared< T >:
Collaboration graph
[legend]

Public Member Functions

 Shared (string name, T value)
 Creates a new shared variable with the given name and value. Must be called from all threads in the parallel region. Acts as a barrier. More...
 
void Dispose ()
 Clears the shared variable from memory. Must be called from all threads in the parallel region. Acts as a barrier. More...
 
virtual void Dispose (bool disposing)
 Clears the shared variable from memory. Virtual implementation for IDisposable interface. More...
 
void Set (T value)
 Sets the value of the shared variable. Is not thread-safe, so user must ensure thread safety. More...
 
Get ()
 Gets the value of the shared variable. More...
 

Static Public Member Functions

static implicit operator T (Shared< T > shared)
 Gets the value of the shared variable. More...
 
static Shared< T > Create< T > (string name, T value)
 Factory method for creating shared variables. More...
 

Static Protected Attributes

static Dictionary< string, dynamic > shared = new Dictionary<string, dynamic>()
 The shared variables. More...
 

Properties

bool Disposed [get, private set]
 Whether or not the shared variable has been disposed. More...
 

Private Attributes

string name
 The name of the shared variable. More...
 

Detailed Description

A shared variable that can be used in a parallel region. This allows for a variable to be declared inside of a parallel region that is shared among all threads, which has some nice use cases.

Factory class for Shared<T>

Template Parameters
TThe type of the shared variable.

Constructor & Destructor Documentation

◆ Shared()

DotMP.Shared< T >.Shared ( string  name,
value 
)
inline

Creates a new shared variable with the given name and value. Must be called from all threads in the parallel region. Acts as a barrier.

Parameters
nameName of the shared variable.
valueInitial starting value of the shared variable.

Member Function Documentation

◆ Create< T >()

static Shared<T> DotMP.Shared< T >.Create< T > ( string  name,
value 
)
inlinestatic

Factory method for creating shared variables.

Template Parameters
TThe type of the shared variable to create.
Parameters
nameThe name of the shared variable.
valueThe value of the shared variable.
Returns
A Shared object.

◆ Dispose() [1/2]

void DotMP.Shared< T >.Dispose ( )
inline

Clears the shared variable from memory. Must be called from all threads in the parallel region. Acts as a barrier.

◆ Dispose() [2/2]

virtual void DotMP.Shared< T >.Dispose ( bool  disposing)
inlinevirtual

Clears the shared variable from memory. Virtual implementation for IDisposable interface.

Parameters
disposingWhether or not to dispose of the shared variable.

◆ Get()

T DotMP.Shared< T >.Get ( )
inline

Gets the value of the shared variable.

Returns
The value of the shared variable.

◆ operator T()

static implicit DotMP.Shared< T >.operator T ( Shared< T >  shared)
inlinestatic

Gets the value of the shared variable.

Parameters
sharedThe shared variable to get the value from.

◆ Set()

void DotMP.Shared< T >.Set ( value)
inline

Sets the value of the shared variable. Is not thread-safe, so user must ensure thread safety.

Parameters
valueThe new value of the shared variable.

Member Data Documentation

◆ name

string DotMP.Shared< T >.name
private

The name of the shared variable.

◆ shared

Dictionary<string, dynamic> DotMP.Shared< T >.shared = new Dictionary<string, dynamic>()
staticprotected

The shared variables.

Property Documentation

◆ Disposed

bool DotMP.Shared< T >.Disposed
getprivate set

Whether or not the shared variable has been disposed.


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