I wrote one application that has a Server class, Client Thread class and Database Thread class.
The Server class has one thread to receive incomming connections. When client connect, the Server class create a Client object. The Database objects was created when the program starts, and its access is from a index Database object array. Each Client has its thread. When the client request some operation to do in database, I select the index of the first free Database object using a Mutex object from a static index variable of Client class. Sometimes, the Client thread seams to be in a dead lock process, and the use of processor goes too high, like an infinite loop.
The part of control source code is :
CApp *p_objApp[T_MAX_CONNECTIONS]; //Database objects
Mutex CCliente::m_Mutex; //Mutext
volatile int CCliente::m_iConeccao; //Database object index selection
I wrote one application that has a Server class, Client Thread class and Database Thread class.
The Server class has one thread to receive incomming connections. When client connect, the Server class create a Client object. The Database objects was created when the program starts, and its access is from a index Database object array. Each Client has its thread. When the client request some operation to do in database, I select the index of the first free Database object using a Mutex object from a static index variable of Client class. Sometimes, the Client thread seams to be in a dead lock process, and the use of processor goes too high, like an infinite loop.
The part of control source code is :
CApp *p_objApp[T_MAX_CONNECTIONS]; //Database objects
Mutex CCliente::m_Mutex; //Mutext
volatile int CCliente::m_iConeccao; //Database object index selection
m_Mutex.EnterMutex();
while( p_objApp[m_iConeccao]->m_fUsing )
{
m_iConeccao ++;
if( m_iConeccao == g_iMaxConeccoes )
m_iConeccao = 0;
}
iConeccao = m_iConeccao;
p_objApp[iConeccao]->m_fUsing = true;
m_iConeccao = 0;
m_Mutex.LeaveMutex();
What's wrong ?
Thanks if anyone can help me.