Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: About OCI thread safety
Herode wrote:
>>>Pass a value of OCI_DEFAULT to OCIEnvCreate(). In this case, the OCI >>>library automatically gets a mutex on every OCI call on the same >>>environment handle." >> >>I think it should be OCI_THREADED and not OCI_DEFAULT. OCI_THREADED >mode would automatically acquire and manage mutexing.
> The following three scenarios are possible, depending on how many
> connections exist in each environment handle, and how many threads will
> be spawned in each connection.
> 1 - If an application has multiple environment handles, but each only
> has one thread (one session exists in each environment handle), no
> mutexing is required.
> 2 - If an application running in OCI_THREADED mode maintains one or
> more environment handles, each of which has multiple connections, it
> also has the following options:
> 2.1 Pass a value of OCI_NO_MUTEX for the mode of OCIEnvCreate(). In
> this case the pplication must mutex OCI calls by made on the same
> environment handle itself. This has the advantage that the mutexing
> scheme can be optimized based on the application design. The programmer
> must also insure that only one OCI call is in process on the
> environment handle connection at any given time.
> 2.2 Pass a value of OCI_DEFAULT to OCIEnvCreate(). In this case, the
> OCI library automatically gets a mutex on every OCI call on the same
> environment handle.
> "
> If you're right, we should read for 2.2 :"Pass a value of
> OCI_THREADED...". But 2 says that the "application is running in
> OCI_THREADED mode". Is there any other way to set a threaded mode tgan
> to pass OCI_THREADED to OCIEnvCreate() ???
>
I'll explain this in a very simple way. If you write a multi-threaded application and want OCI to take care of threading (mutexing etc.) you create the environment in OCI_THREADED mode. If you write a multi-threaded application and do not want OCI to automatically mutex OCI calls, and want to serialize/mutex them yourself, you simply pass OCI_THREADED + OCI_NO_MUTEX to OCIEnvCreate. As simple as that.
You can contact support to check if this is/not a doc bug.
>
>> > Users who do not write multithreaded programs do not pay a performance >> > penalty for using thread-safe OCI calls." >> >>Yes! It simply means that the threading feature will not affect somebody >>whos writing a non-threaded application, taken that the environment is >>created in the OCI_DEFAULT mode. >>
>
> But OCI_DEFAULT is not a "thread safe OCI call" : it does not manage
> mutexes. Or is there any other way to be thread safe ???
>
Just say OCI_THREADED to OCIEnvCreate to be thread safe.
>
>> > And a few lines below : >> > "If an application is single-threaded, whether or not the platform is >> > thread-safe, the application should pass a value of OCI_DEFAULT to >> > OCIInitialize() or OCIEnvCreate(). Single-threaded applications which >> > run in OCI_THREADED mode may incur performance hits." >> > >> > So what ?????? >> >>Yes! The application would incur a performance hit because it's single >>threaded and still uses OCI_THREADED as the mode. Think of all the >>unnecessary mutexing. >>
Rgds.
Amogh
Received on Wed Apr 26 2006 - 07:48:21 CDT
![]() |
![]() |