Sorry for all my previous posts

let me explain the exact problem

There is a singleton object in the shared memory. It conatins a pool of connection objects to a server. (more likely an array of connection objects).
I want to go through the array and find which connection object is free to access.

Then that particular object is locked, used for connection and then unlocked.
The following is the singleton object which encapsulates the connection pool array.

class single
{
private:
~single();
single();
connectionObj[5];
public:
connectionObj & GetConnectionObj() ;
void Lock();
void UnLock();
}

There are at least 8 processes that are simultaneously accessing the singleton object.

I want a synchronization between all these process and want to implement GetconnectionObj() function. How to implement it and where the locks must be used.

Should the locks be while accessing singleton object or while acessing the connection object, or both

please explain me with the help of code

Thanks in advance

Regards
VADAN