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 :

Qt Code:
  1. PASSTHRU_MSG* QTCanMonitor::GetMessageDetail( unsigned long *pulNumMsgs, int iChannelIndex )
  2. {
  3. unsigned long ulTimeout = 0;
  4. int iReply = -1;
  5.  
  6. if( m_pPassThruReadMsgs && m_bConnected )
  7. {
  8. iReply = (m_pPassThruReadMsgs)( m_lChannelID[iChannelIndex], m_CanMsg, pulNumMsgs, ulTimeout );
  9. if( iReply == -1 )
  10. {
  11. return NULL;
  12. }
  13. }
  14. else
  15. return NULL;
  16. return m_CanMsg;
  17. }
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