BDE 4.14.0 Production release
|
Macros | |
#define | BSLMT_THREAD_LOCAL_VARIABLE(BASIC_TYPE, VARIABLE_NAME, INITIAL_VALUE) static BSLMT_THREAD_LOCAL_KEYWORD BASIC_TYPE VARIABLE_NAME = INITIAL_VALUE; |
#define | BSLMT_THREAD_LOCAL_KEYWORD __thread |
Provide a macro to declare a thread-local variable.
This component should not be used outside of the bslmt
package at this time.
This component defines a macro for declaring a static
thread-local variable. Where a normal static variable is located at the same memory location for all threads within a process, a thread-local static variable has a different memory location for each thread in the process:
Note that, BSLMT_THREAD_LOCAL_VARIABLE
should not be instantiated at class scope.
This section illustrates intended use of this component.
In the following example we create a RequestProcessor
that places context information for the current request in a thread-local variable.
First, we define a trivial structure for a request context.
Next, we create a trivial RequestProcessor
that provides a static
class method that returns the RequestContext
for the current thread, or 0 if the current thread is not processing a request.
Now, we define the contextReference
method, which defines a thread-local RequestContext
pointer, context
, initialized to 0, and returns a reference providing modifiable access to that pointer.
Then, we define the processRequest
method, which first sets the thread-local pointer containing the request context, and then processes the request
.
Finally, we define a separate function myFunction
that uses the RequestProcessor
class to access the RequestContext
for the current thread.
#define BSLMT_THREAD_LOCAL_KEYWORD __thread |
#define BSLMT_THREAD_LOCAL_VARIABLE | ( | BASIC_TYPE, | |
VARIABLE_NAME, | |||
INITIAL_VALUE | |||
) | static BSLMT_THREAD_LOCAL_KEYWORD BASIC_TYPE VARIABLE_NAME = INITIAL_VALUE; |
Define, at function or namespace scope, a thread-local static
variable having the specified VARIABLE_NAME
of the specified BASIC_TYPE
, initialized with the specified INITIAL_VALUE
. If VARIABLE_NAME
is not a valid variable name, or INITIAL_VALUE
is not convertible to the type BASIC_TYPE
, the instantiation of this macro will result in a compile time error. The behavior is undefined unless INITIAL_VALUE
is a compile time constant value.