Class: TSynchronized

Declaration: Synchronized.h

Taxonomy Categories:

Member Functions:


Interface Category:

API.

Inherits From:

TSynchronizedBase.

Inherited By:

None.

Purpose:

Provides non-blocking concurrent access to data.

Instantiation:

Instantiate using static linkage to get automatic C-style initialization. If instantiated on the heap or on the stack, it is the creator's responsibility to initialize the synchronized datum using the Set() member function.

Deriving Classes:

No classes derive from TSynchronized.

Concurrency:

Multithread safe.

Resource Use:

No special requirements.

Other Considerations:

TSynchronized may only be used to hold data that can be converted to and from a void pointer. Otherwise, you'll get compilation errors. Note that TSynchronized objects should be instantiated with static linkage to get automatic C-style initialization. This is the reason that TSynchronized does not have a constructor: it is an aggregate type, so static TSynchronized objects will be initialized to zero. If a TSynchronized object is instantiated on the stack or on the heap, the creator is responsible for initializing the object using the Set() member function.

Member Function: TSynchronized::Get

AType Get () const

Interface Category:

API.

Purpose:

Atomically fetches the value of a synchronized datum.

Calling Context:

Called by clients to read the value of a synchronized datum.

Parameters:

Return Value:

Returns the value of a synchronized datum.

Exceptions:

Throws no exceptions.

Concurrency:

Multithread safe.

Other Considerations:

A TSynchronized object can be used in rvalue contexts (where the value of its template type would be read) because it contains a type conversion operator. Get() and operator AType() are synonymous.

Member Function: TSynchronized::operatorAType

operator AType () const

Interface Category:

API.

Purpose:

Atomically fetches the value of a synchronized datum.

Calling Context:

Invoked by the compiler when a TSynchronized object is used in the context of its template type.

Parameters:

Return Value:

Returns the value of a synchronized datum.

Exceptions:

Throws no exceptions.

Concurrency:

Multithread safe.

Other Considerations:

This operator is synonymous with the Get() member function.

Member Function: TSynchronized::SetConditional

bool SetConditional (AType test, AType newValue)

Interface Category:

API.

Purpose:

Conditionally change a synchronized datum's value atomically.

Calling Context:

Called by clients to safely and atomically change the value of a synchronized datum.

Parameters:

Return Value:

Returns true if the value was not set, false if the value was set.

Exceptions:

Throws no exceptions.

Concurrency:

Multithread safe.

Other Considerations:

The sense of the return value is useful for retrying SetConditional in a loop (think of it as a "retry" indication): do { /* insert "nice" delay here */ oldValue =aSynchronizedValue.Get(); } while (aSynchronizedValue.SetConditional(oldValue, newValue));

Member Function: TSynchronized::Set

void Set (AType newValue)

Interface Category:

API.

Purpose:

Atomically set a synchronized datum.

Calling Context:

Called by clients to atomically set a synchronized datum.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions.

Concurrency:

Multithread safe.

Other Considerations:

Use SetConditional to atomically change the value of a synchronized datum from a known value.
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.