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
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
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
RadioButtonList data selection
view plaincopy to clipboardprint?http to https
Hi,
Is there any specific method/condition to move an http:// page to https:// ?
Batch Related Pricing
Hi, I need some clarity on the batch related pricing
For example the following are the b
Code working in IE but not FireFox
I created a dynamic navigation list for my website based off of a table in my database. The code is
php code generators
All
Whilst enjoying learning a new language i have come accross a number of free code generat
Filename like the user name
I am creating a form and storing the values in file. Could anyone please tell me how to write a code
MS are the best!!!
Visit http://www.microsoft.com/australia/windows/default.aspx?h=watch-a-demo and click the massive '
PHP Redirecting
Hello everyone. Is there a way to redirect people to pages within a statement in PHP? Since there is
Not adding to db
Hi, I can't figure out why it won't add the record to the database. It's just a simple form to get