• C

HERE!! :-) Thread safe abstraction layer

I've got to develop a database abstraction layer to be used with Oracle and PostgreSQL. It'll have to be fast, so I'm using a bunch of ifdefs and letting the compiler do the work. (so, only one will be compiled).

ODBC is not an option because we need native data handling.

The problem is that this abstraction layer must be fully transparent (IE, the program will call just one function without taking care of handle casts) AND thread safe (we'll open more than one connection -- will be using posix threads).

There's more than one function, so the easiest solution would be placing a global variable for the connection handle/result, but this would break the thread safety. Another option is to give/get the handle variables from/to the functions, but this would break the "full transparency" of the abstraction layer, which is (unfortunatelly) essential to the project.

I'd like to hear you suggestions. If necessary, I can post some of the code here or email it to you.

Thanks a lot.
suguinhaAsked:
Who is Participating?
 
andymurdConnect With a Mentor Commented:
You could try using thread local storage to provide a "global" variable per thread. Look for pthread_key_create() on *nix and TlsAlloc() on win32.

Its a pretty icky solution though. I'd prefer to specify an environment, connection or cursor handle to each function.
0
 
suguinhaAuthor Commented:
Thanks, we've switched to multiple processes/IPC model.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.