Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: About OCI thread safety

Re: About OCI thread safety

From: Amogh <amogh.r_at_nospam.com>
Date: Wed, 26 Apr 2006 18:18:21 +0530
Message-ID: <RfK3g.23$Fk3.106@news.oracle.com>


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.

>
> May be it's a typo, but if it is, I stuill don't understand what they
> say. The complete section with its context is :
> "

> 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.
>>

>
> You're right, this one is obvious. Of course, as I am not an english
> native speaker, I might have misunderstood some sentences. But, in the
> way I undestand it, it seems to me that this documentation is
> inconsistent.
>
> Thanks for replying anyway. I don't ask these questions just to split
> hairs. I'm really and heavily stuck on memory and thread bogues in an
> OCI application, and I'm looking for all information able to help me to
> get out of this... ;o)
>

Rgds.
Amogh Received on Wed Apr 26 2006 - 07:48:21 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US