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;
}
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;
}
To copy to clipboard, switch view to plain text mode
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
Bookmarks