T
tiffini
Hi,
We have a lot of OS's to support. So we created a mutex class with sieze and release like so
class foo{
private:
volatile int m_lock;
public:
Sieze(){ while (m_lock==1) { sleep(1);};m_lock=1;};
Release(){m_lock=0;};
.... // constructors etc
}
Is this legal or do I have to use an OS type call? I thought that volatile guaranteed m_lock to be thread safe, meaning the variable m_lock could not be cashed in a register if the thread was swapped out for another thread.
thanks in advance
tif
We have a lot of OS's to support. So we created a mutex class with sieze and release like so
class foo{
private:
volatile int m_lock;
public:
Sieze(){ while (m_lock==1) { sleep(1);};m_lock=1;};
Release(){m_lock=0;};
.... // constructors etc
}
Is this legal or do I have to use an OS type call? I thought that volatile guaranteed m_lock to be thread safe, meaning the variable m_lock could not be cashed in a register if the thread was swapped out for another thread.
thanks in advance
tif