Table 17-5 lists the thread management functions that are described in this section.
Table 17-5 Thread Management Functions
Function | Purpose |
---|---|
Close a thread handle |
|
Create a new thread |
|
Retrieve the OCIThreadHandle of the thread in which it is called |
|
Destroy and deallocate the thread handle |
|
Allocate and initialize the thread handle |
|
Destroy and deallocate a thread ID |
|
Retrieve the |
|
Allocate and initialize the thread ID |
|
Determine whether a given |
|
Determine whether two |
|
Set one |
|
Set the |
|
Initialize OCIThread context |
|
Tell the caller whether the application is running in a multithreaded environment or a single-threaded environment |
|
Allow the calling thread to join with another thread |
|
Destroy and deallocate the key pointed to by |
|
Get the calling thread's current value for a key |
|
Create a key |
|
Set the calling thread's value for a key |
|
Acquire a mutex for the thread in which it is called |
|
Destroy and deallocate a mutex |
|
Allocate and initialize a mutex |
|
Release a mutex |
|
Perform OCIThread process initialization |
|
Release the OCIThread context |
The OCI environment or user session handle.
The OCI error handle. If there is an error, it is recorded in err
and this function returns OCI_ERROR
. Diagnostic information can be obtained by calling OCIErrorGet().
The OCIThread thread handle to close.
The tHnd
parameter should be initialized by OCIThreadHndInit(). Both the thread handle and the thread ID that was returned by the same call to OCIThreadCreate() are invalid after the call to OCIThreadClose()
.
sword OCIThreadCreate ( void *hndl, OCIError *err, void (*start) (void *), void *arg, OCIThreadId *tid, OCIThreadHandle *tHnd );
The OCI environment or user session handle.
The OCI error handle. If there is an error, it is recorded in err
and this function returns OCI_ERROR
. Diagnostic information can be obtained by calling OCIErrorGet().
The function in which the new thread should begin execution.
The argument to give the function pointed to by start
.
If not NULL
, gets the ID for the new thread.
If not NULL
, gets the handle for the new thread.
The new thread starts by executing a call to the function pointed to by start
with the argument given by arg
. When that function returns, the new thread terminates. The function should not return a value and should accept one parameter, a void
. The call to OCIThreadCreate()
must be matched by a call to OCIThreadClose() if and only if tHnd
is non-NULL
.
If tHnd
is NULL
, a thread ID placed in *tid
is not valid in the calling thread because the timing of the spawned threads termination is unknown.
The tid
parameter should be initialized by OCIThreadIdInit() and tHnd
should be initialized by OCIThreadHndInit().
The OCI environment or user session handle.
The OCI error handle. If there is an error, it is recorded in err
and this function returns OCI_ERROR
. Diagnostic information can be obtained by calling OCIErrorGet().
If not NULL
, the location to place the thread handle for the thread.
The tHnd
parameter should be initialized by OCIThreadHndInit().
The thread handle tHnd
retrieved by this function must be closed with OCIThreadClose() and destroyed by OCIThreadHndDestroy() after it is used.
The OCI environment or user session handle.
The OCI error handle. If there is an error, it is recorded in err
and this function returns OCI_ERROR
. Diagnostic information can be obtained by calling OCIErrorGet().
The address of pointer to the thread handle to destroy.
The thnd
parameter should be initialized by OCIThreadHndInit().
The OCI environment or user session handle.
The OCI error handle. If there is an error, it is recorded in err
and this function returns OCI_ERROR
. Diagnostic information can be obtained by calling OCIErrorGet().
The address of the pointer to the thread handle to initialize.
The OCI environment or user session handle.
The OCI error handle. If there is an error and OCI_ERROR
is returned, the error is recorded in err
and diagnostic information can be obtained by calling OCIErrorGet().
Pointer to the thread ID to destroy.
The tid
parameter should be initialized by OCIThreadHndInit().
The OCI environment or user session handle.
The OCI error handle. If there is an error, it is recorded in err
and this function returns OCI_ERROR
. Diagnostic information can be obtained by calling OCIErrorGet().
This should point to the location in which to place the ID of the calling thread.
The tid
parameter should be initialized by OCIThreadHndInit(). When OCIThread is used in a single-threaded environment, OCIThreadIdGet()
always places the same value in the location pointed to by tid
. The exact value itself is not important. The important thing is that it is different from the NULL
thread ID and that it is always the same value.
The OCI environment or user session handle.
The OCI error handle. If there is an error and OCI_ERROR
is returned, the error is recorded in err
and diagnostic information can be obtained by calling OCIErrorGet().
Pointer to the thread ID to initialize.
The OCI environment or user session handle.
The OCI error handle. If there is an error, it is recorded in err
and this function returns OCI_ERROR
. Diagnostic information can be obtained by calling OCIErrorGet().
Pointer to the OCIThreadId
to check.
Pointer to the result.
If tid
is the NULL
thread ID, result
is set to TRUE
. Otherwise, result
is set to FALSE
. The tid
parameter should be initialized by OCIThreadIdInit().
sword OCIThreadIdSame ( void *hndl, OCIError *err, OCIThreadId *tid1, OCIThreadId *tid2, boolean *result );
The OCI environment or user session handle.
The OCI error handle. If there is an error, it is recorded in err
and this function returns OCI_ERROR
. Diagnostic information can be obtained by calling OCIErrorGet().
Pointer to the first OCIThreadId
.
Pointer to the second OCIThreadId
.
Pointer to the result.
If tid1
and tid2
represent the same thread, result
is set to TRUE
. Otherwise, result
is set to FALSE
. The result
parameter is set to TRUE
if both tid1
and tid2
are the NULL
thread ID. The parameters tid1
and tid2
should be initialized by OCIThreadIdInit().
sword OCIThreadIdSet ( void *hndl, OCIError *err, OCIThreadId *tidDest, OCIThreadId *tidSrc );
The OCI environment or user session handle.
The OCI error handle. If there is an error and OCI_ERROR
is returned, the error is recorded in err
and diagnostic information can be obtained by calling OCIErrorGet().
This should point to the location of the OCIThreadId
to set to.
This should point to the OCIThreadId
to set from.
The tid
parameter should be initialized by OCIThreadIdInit().
The OCI environment or user session handle.
The OCI error handle. If there is an error, it is recorded in err
and this function returns OCI_ERROR
. Diagnostic information can be obtained by calling OCIErrorGet().
This should point to the OCIThreadId
in which to put the NULL
thread ID.
The tid
parameter should be initialized by OCIThreadIdInit().
The OCI environment or user session handle.
The OCI error handle. If there is an error and OCI_ERROR
is returned, the error is recorded in err
and diagnostic information can be obtained by calling OCIErrorGet().
It is illegal for OCIThread clients to try to examine the memory pointed to by the returned pointer. It is safe to make concurrent calls to OCIThreadInit()
. Unlike OCIThreadProcessInit(), there is no need to have a first call that occurs before all the others.
The first time OCIThreadInit()
is called, it initializes the OCIThread context. It also saves a pointer to the context in some system-dependent manner. Subsequent calls to OCIThreadInit()
return the same context.
Each call to OCIThreadInit()
must eventually be matched by a call to OCIThreadTerm().
Tells the caller whether the application is running in a multithreaded environment or a single-threaded environment.
The OCI environment or user session handle.
The OCI error handle. If there is an error, it is recorded in err
and this function returns OCI_ERROR
. Diagnostic information can be obtained by calling OCIErrorGet().
The OCIThreadHandle
of the thread to join with.
This function blocks the caller until the specified thread terminates.
The tHnd
parameter should be initialized by OCIThreadHndInit(). The result of multiple threads all trying to join with the same thread is undefined.
The OCI environment or user session handle.
The OCI error handle. If there is an error and OCI_ERROR
is returned, the error is recorded in err
and diagnostic information can be obtained by calling OCIErrorGet().
The OCIThreadKey
in which to destroy the key.
This is different from the destructor function callback passed to the key create routine. The function OCIThreadKeyDestroy()
is used to terminate any resources that the OCIThread acquired when it created key
. The OCIThreadKeyDestFunc
callback of OCIThreadKeyInit() is a key value destructor; it does not operate on the key itself.
This must be called after the user has finished using the key. Not calling the OCIThreadKeyDestroy()
function may result in memory leaks.
The OCI environment or user session handle.
The OCI error handle. If there is an error and OCI_ERROR
is returned, the error is recorded in err
and diagnostic information can be obtained by calling OCIErrorGet().
The key.
The location in which to place the thread-specific key value.
It is illegal to use this function on a key that has not been created using OCIThreadKeyInit().
If the calling thread has not yet assigned a value to the key, NULL
is placed in the location pointed to by pValue
.
sword OCIThreadKeyInit (void *hndl, OCIError *err, OCIThreadKey **key, OCIThreadKeyDestFunc destFn );
The OCI environment or user session handle.
The OCI error handle. If there is an error and OCI_ERROR
is returned, the error is recorded in err
and diagnostic information can be obtained by calling OCIErrorGet().
The OCIThreadKey
in which to create the new key.
The destructor for the key. NULL
is permitted.
Each call to this routine allocates and generates a new key that is distinct from all other keys. After this function executes successfully, a pointer to an allocated and initialized key is returned. That key can be used with OCIThreadKeyGet() and OCIThreadKeySet(). The initial value of the key is NULL
for all threads.
It is illegal for this function to be called more than once with the same value for the key
parameter.
If the destFn
parameter is not NULL
, the routine pointed to by destFn
is called whenever a thread that has a non-NULL
value for the key terminates. The routine is called with one parameter. The parameter is the key's value for the thread at the time at which the thread terminated. If the key does not need a destructor function, pass NULL
for destFn
.
The OCI environment or user session handle.
The OCI error handle. If there is an error and OCI_ERROR
is returned, the error is recorded in err
and diagnostic information can be obtained by calling OCIErrorGet().
The key.
The thread-specific value to set in the key.
It is illegal to use this function on a key that has not been created using OCIThreadKeyInit().
The OCI environment or user session handle.
The OCI error handle. If there is an error, it is recorded in err
and this function returns OCI_ERROR
. Diagnostic information can be obtained by calling OCIErrorGet().
The mutex to acquire.
If the mutex is held by another thread, the calling thread is blocked until it can acquire the mutex.
It is illegal to attempt to acquire an uninitialized mutex.
This function's behavior is undefined if it is used by a thread to acquire a mutex that is already held by that thread.
The OCI environment or user session handle.
The OCI error handle. If there is an error and OCI_ERROR
is returned, the error is recorded in err
and diagnostic information can be obtained by calling OCIErrorGet().
The mutex to destroy.
Each mutex must be destroyed after it is no longer needed.
It is not legal to destroy a mutex that is uninitialized or is currently held by a thread. The destruction of a mutex must not occur concurrently with any other operations on the mutex. A mutex must not be used after it has been destroyed.
The OCI environment or user session handle.
The OCI error handle. If there is an error and OCI_ERROR
is returned, the error is recorded in err
and diagnostic information can be obtained by calling OCIErrorGet().
The mutex to initialize.
All mutexes must be initialized before use.
Multiple threads must not initialize the same mutex simultaneously. Also, a mutex must not be reinitialized until it has been destroyed (see OCIThreadMutexDestroy()
).
The OCI environment or user session handle.
The OCI error handle. If there is an error and OCI_ERROR
is returned, the error is recorded in err
and diagnostic information can be obtained by calling OCIErrorGet().
The mutex to release.
If there are any threads blocked on the mutex, one of them acquires it and becomes unblocked.
It is illegal to attempt to release an uninitialized mutex. It is also illegal for a thread to release a mutex that it does not hold.
Whether this function must be called depends on how OCIThread is going to be used.
In a single-threaded application, calling this function is optional. If it is called at all, the first call to it must occur before calls to any other OCIThread functions. Subsequent calls can be made without restriction; they do not have any effect.
In a multithreaded application, this function must be called. The first call to it must occur strictly before any other OCIThread calls; that is, no other calls to OCIThread functions (including other calls to this one) can be concurrent with the first call.
Subsequent calls to this function can be made without restriction; they do not have any effect.
The OCI environment or user session handle.
The OCI error handle. If there is an error and OCI_ERROR
is returned, the error is recorded in err
and diagnostic information can be obtained by calling OCIErrorGet().
This function should be called exactly once for each call made to OCIThreadInit().
It is safe to make concurrent calls to OCIThreadTerm()
. OCIThreadTerm()
does not do anything until it has been called as many times as OCIThreadInit() has been called. When that happens, OCIThreadTerm()
terminates the OCIThread layer and frees the memory allocated for the context. Once this happens, the context should not be reused. It is necessary to obtain a new one by calling OCIThreadInit().