Re: thread safe sqlca-value

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: 1999/10/30
Message-ID: <WgUbOAm56n3Jw3=2lqpdcv7tPDMV_at_4ax.com>#1/1


A copy of this was sent to Roland <e9426992_at_stud4.tuwien.ac.at> (if that email address didn't require changing) On Sat, 30 Oct 1999 08:56:20 +0200, you wrote:

>Hi!
>
>I am developing a multi-threaded server (in c) using oracle pro*c to
>access an oracle-db on linux, using oracle 8.0.5.
>
>If i have lots of threads, do I have to mutex the sqlca accesses or not?
>I have 1 session context, but more than 1 accesses to the database, and
>the threads
>are pretty complex (they call lots of functions), so in the end: i do
>not know WHAT action a thread at a given time does perform.
>
>As far as I could figure out, the sqlca datastructure is the only
>dangerous part, is this correct?
>
>Thanks for ur help!
>Roland.

Just make sure each subroutine puts the sqlca on the stack -- not in the data -- so you don't have to mutex around every call. eg:

#include <stdio.h>
#include <string.h>

#define SQLCA_INIT
EXEC SQL INCLUDE sqlca; // defines a GLOBAL one, but we won't use that one

static int process( char * tname )
{

struct sqlca sqlca;    // gives this subroutine its own sqlca
                       // all proc calls pass the &sqlca down to the 
                       // lower level stuff so this makes it threadsafe
                       // since C scoping rules will have us passing the 
                       // address of our stack variable -- not the single
                       // global above.  If you have an error routine, you'll
                       // have to pass it this structure of course, not just
                       // refer to the global sqlca struct as that one will 
                       // not be used.

EXEC SQL BEGIN DECLARE SECTION;
    varchar     c[8][10];

EXEC SQL END DECLARE SECTION;     .......
-- 
See http://osi.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'...
Current article is "Part I of V, Autonomous Transactions" updated June 21'st
 
Thomas Kyte                   tkyte_at_us.oracle.com
Oracle Service Industries     Reston, VA   USA

Opinions are mine and do not necessarily reflect those of Oracle Corporation
Received on Sat Oct 30 1999 - 00:00:00 CEST

Original text of this message