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 Like 15 Dislike
Previous forums Next forums
Other forums

using explode() to fill in checkboxes
Hi

I have a field stored in a table that contains regions in the UK separated by commas. Ther

PHP webpage & array print issue
I have this code running, and it works perfectly … however, see my bottom bit about what I see

Inserting the current date/time while submitting the forum
What do I need to add below to update the current date/time? I have a field in the database called d

[function.file]: failed to open stream: No such file or directory
Okay I wrote this little script to upload a csv file that is located on my webhosts server to a mysq

* Gridview and Detailsview in UpdatePanel, insert mode problem
I have a GridView and DetailsView working together. When a record from Gridview is selected, Detail

Best PHP Documentation generator
Hello guys!

I would like to hear from you what is the best PHP documentation generator. Perso

Add 5 to a variable when a button is clicked, and re-run a for loop
So I'm making a feedback sort of section on a website with MySQL and PHP, I've gotten the script to

Delete Client 066 Earlywatch
Hi all,

in former times client earlywatch was required for SAPs remote access to SAP inst

session variables not working anymore
hello,
i use sessions to handle authentication within my site. my host has been changing a lot of

How to use Ajax to verify data on a DB ?
Hello everyone, well i want to know how to check a value if it exists or not on a Data base and capt

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash