steg90
19th July 2007, 07:49
Hi,
I have a function called GetMessageDetail which returns a pointer to a structure. This method is called from two separate threads, the function is as follows :
PASSTHRU_MSG* QTCanMonitor::GetMessageDetail( unsigned long *pulNumMsgs, int iChannelIndex )
{
unsigned long ulTimeout = 0;
int iReply = -1;
if( m_pPassThruReadMsgs && m_bConnected )
{
iReply = (m_pPassThruReadMsgs)( m_lChannelID[iChannelIndex], m_CanMsg, pulNumMsgs, ulTimeout );
if( iReply == -1 )
{
return NULL;
}
}
else
return NULL;
return m_CanMsg;
}
What would be the best way to make sure this method is not accessed by the two threads at the same time? Would a QMutex be ok?
Thanks,
Steve
I have a function called GetMessageDetail which returns a pointer to a structure. This method is called from two separate threads, the function is as follows :
PASSTHRU_MSG* QTCanMonitor::GetMessageDetail( unsigned long *pulNumMsgs, int iChannelIndex )
{
unsigned long ulTimeout = 0;
int iReply = -1;
if( m_pPassThruReadMsgs && m_bConnected )
{
iReply = (m_pPassThruReadMsgs)( m_lChannelID[iChannelIndex], m_CanMsg, pulNumMsgs, ulTimeout );
if( iReply == -1 )
{
return NULL;
}
}
else
return NULL;
return m_CanMsg;
}
What would be the best way to make sure this method is not accessed by the two threads at the same time? Would a QMutex be ok?
Thanks,
Steve