Solved

HERE!! :-)   Thread safe abstraction layer

Posted on 2002-07-08
2
257 Views
Last Modified: 2010-04-15
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.
0
Comment
Question by:suguinha
2 Comments
 
LVL 1

Accepted Solution

by:
andymurd earned 500 total points
Comment Utility
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
 

Author Comment

by:suguinha
Comment Utility
Thanks, we've switched to multiple processes/IPC model.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Absolute madness with managing time in C 4 80
How to create project in Eclipse ? 1 183
How to organize data in excel ? 2 106
Adjust Mfcapp 29 154
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now