A question about OCI_THREADED.
600577Oct 16 2007 — edited Oct 25 2007I have just tested a simple C code and found a strange behavior I don't understand. The code looks like,
void* fn( void* arg )
{
OCIEnv* envhp;
OCIError* errhp;
OCIServer* svrhp;
...
OCIEnvCreate( OCI_DEFAULT );
OCIHandleAlloc() ...
OCIServerAttach( );
...
}
int main()
{
for( i=0; i=64; i++ )... (pthread_create(fn); )
join_all();
return 1;
}
It's a very simple code that attempts to establish multiple sessions using threads.
As far as I understand, as each thread is using its own environment and no two sessions are sharing the same envinrmnent handle, I do not need to set OCI_THREADED flag when calling OCIEnvCreate. But when I create more than about 10~15 threads with OCI_DEFAULT, it always crashes at OCIServerAttach. With OCI_THREADED, ok.
However, what is more strange is that if I manually serialize connection establishment phase using mutex without OCI_THREADED option, everything works well afterwards.
Am I missing something?