Multithreading design
Posted on
16th Feb 2014 07:03 pm by
admin
Hi
I have come up with a Singleton class that manages a pool of database connections. Basically the pool is a queue in which I have stored some connection objects. When ever a client calls any of the database class methods a connection object is popped from the queue and when done the connection is pushed on the queue. If the there are no more connections then that thread has to wait for signal when the pool has a connection then a signal is broadcasted to the wait thread. And now some code
Did you know?Explore Trending and Topic pages for more stories like this.
Code: if(dbPool.size() != 0)
{
pthread_mutex_lock(&criticalSection);
DNativeDb activeDbObj = dbPool.pop();
pthread_mutex_lock(&criticalSection);
...
}First Question: Is it ok to put pop() under the a mutex_lock
elsewhere in code
Code: pthread_mutex_lock(&criticalSection);
dbPool.push(activeObj);
if(dbPool.size() == 1)
{
pthread_cond_broadcast(&cond);
}
thread_mutex_lock(&criticalSection);Second: When my pool has 1 connection object left then I need to broadcast incase some thread that might be waiting can then acquire the object. Is this the right way to achieve pool based connecting handling. Please guide and suggest if I am going wrong anywhere.
Thanks
No comments posted yet
Your Answer:
Login to answer
198
15
Other forums
Format timestamp from mysql
When I tried this:
Code: date("m/d/Y H:i A", $row['timestamp'])
I got 12/31/1969 18:
what business processes?
Hi,
A general question. What business processes (like OTC - Order to Cach, P2P, R2R etc)
php or sql?
Sorry not sure if this is a sql problem or php the following code is supposed to delete data from th
Internal Server Error issues
This has been bothering me for weeks and I've been trying to solve it without asking for help, but e
mySQL and PHP search
Hello,
I am trying to code a project and ran into a brick wall with one of my pages. I am pretty
Am I setting up my sites oldschool?
Ok,
When I create a site I open a basic template that I have created that consists of a css f
WS-Security PL/SQL Forms
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Prod
PL/SQL Release 10.2.0.2.0 - P
RSS feed - FeedList for WordPress
Hi,
I'm trying to alter the FeedList plugin for WordPress so that I can click on the title of
Progress bar tracking file downloads
Hey guys, was wondering if there was a way to track how far a file has been downloaded. I know there
cookie problem
I hv a website url
In this site main menu functionality based on cookie when user click on parti