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

How could I do this?
Ive got a simple lottery game, and am using an sql database to keep track of the numbers bought. But

Allowing ' and "
Hello everyone,

I am creating a form where users submit information to go into a database. I

MySQL noob question
hi guys

I have a simple mysql table set up, along the lines of

Col 1 - Col 2 - Date_l

HeaderSelectedCssClass not working
I have an accordian where I have a drop down list in the first pane and a grid in the second pane.

Remove Rows From Database ad
Hi All,

I have this:

Code: [Select]<?php
session_start();
include('../com

Array becomes unset by itself?
Hi,

I have a bit of experience with PHP but not extensive. It seems I cannot store any items

Loops and Classes
I am making a template system and everything seems to be going well up until I have to loop in a var

Do While statement
hi guys,

This may sound trivial but im new to php and as part of an assignmenti have to const

Not connecting to DB using ruby, error:env.c:257:in oci8lib.so: ORA-12154:
Hi All,

I am trying to connect to the database server from the client server using ruby and f

Problem in OnClientClick and OnClick sync
Hi,Strange and irritating problem: I have below button declaration in markup of the aspx page:

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