Home » Developer & Programmer » Precompilers, OCI & OCCI » OCI Multithread in HPUX (OCI, 9.2, HPUX)
OCI Multithread in HPUX [message #345183] Tue, 02 September 2008 09:20
texas
Messages: 1
Registered: September 2008
Junior Member
I'm migrating a server to OCI and have come across two problems:

Using pthreads, my OCI calls are not thread safe at all, I have to place mutexes when executing statements, getting sessions, etc. By placing these mutexes almost everywhere there is an OCI call, it almost never crashes, but yet it still does, and alwways in OCI calls. (code is below)


Not knowing what to do I tryed to use OCIThreads in hope the OCIThread package did something more, something I was missing. Different problem now, after 254 threads are executed, OCIThreadCreate() does not work anymore. The same problem exists with pthreads when you forget to invoke pthread_exit() when terminating the thread. OCIThreadClose does not solve the problem. What is the right procedure??

Thanks
Comments welcome

Code:
pthreads stuff:

Main{
OCIEnvCreate (&m_environment, OCI_THREADED , (dvoid *)0, NULL,
NULL, NULL, 0, (dvoid **)0);

(void) OCIHandleAlloc((dvoid *) m_environment, (dvoid **) &error, OCI_HTYPE_ERROR,
(size_t) 0, (dvoid **) 0);

(void) OCIHandleAlloc((dvoid *) m_environment, (dvoid **) &m_connPool, OCI_HTYPE_CPOOL,
(size_t) 0, (dvoid **) 0);

if (lstat = OCIConnectionPoolCreate(m_environment,
error,m_connPool, &poolName, &poolNameLen,
(const unsigned char *)m_connectString->c_str(),(sb4)m_connectString->length(),
m_minConn, m_maxConn, m_incrConn,
(const unsigned char *)m_userName->c_str() (sb4)m_userName->length(),
(const unsigned char *)m_password->c_str(),(sb4)m_password->length()
,OCI_DEFAULT))

{
checkerr(error,lstat);
exit(1);
TR_END_I(localfunction);
}
m_poolName=new string((char *)poolName);
OCIThreadProcessInit ();
OCIThreadInit(m_environment, error);
while(){
...
}
}

ONCall(){

pthread_attr_t thread_attr;
pthread_attr_init(&thread_attr);
pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
int iThreadResult=pthread_create(&thread,&thread_attr,threadProc,(void *) &r);

}

void* threadProc(void* vp){

m_error=NULL;
(void) OCIHandleAlloc((dvoid *) m_environment, (dvoid **) &m_error, OCI_HTYPE_ERROR,
(size_t) 0, (dvoid **) 0);

if (lstat = OCILogon2(m_environment, m_error, &m_session,
(CONST OraText *)m_userName->c_str(), (ub4)m_userName->length(),
(CONST OraText *)m_password->c_str(), (ub4)m_password->length(),
(CONST OraText *)m_poolName->c_str(), (ub4)m_poolName->length(),
OCI_CPOOL))
{
pthread_mutex_unlock(&mutexConnection);
checkerr(m_error,lstat);
}

/*DO THE OCI STUFF ****************************/

OCILogoff ( m_session, m_error );
OCIHandleFree( m_error,OCI_HTYPE_ERROR);

pthread_exit((void *)pthread_self());
// return 0;
}


-----------------------------------------------------------------
OCITthreads Stuff:

thread creation:
...
if(checkerr(OCIRoot::m_error,OCIThreadCreate(OCIRoot::m_environment, OCIRoot::m_error, threadProcess, (void *) &r, NULL, NULL)))
{
TR_LOG("NEW OCIThread")<<endt;
TR_LOG("NEW OCIThread")<<threadCounter++<<endt;

isThread=1;
}
...



thread(){
...
OCIThreadHandle *threadHandle;
OCIThreadHndInit(OCIRoot::m_environment, OCIRoot::m_error, &threadHandle);
OCIThreadHandleGet(OCIRoot::m_environment, OCIRoot::m_error, threadHandle);

OCIThreadClose(OCIRoot::m_environment, OCIRoot::m_error, threadHandle);

}



Previous Topic: PCC-S-02322, found undefined identifier
Next Topic: Compile pro*c file with "-DDAEMON -DBACKGROUND" option on Solaris
Goto Forum:
  


Current Time: Thu Nov 21 11:41:28 CST 2024