I'm writing simple cycle code which needs check simple custom thread lock, and when this lock is passed thread will continue
static bool* lock;
...
while (*lock);
// TODO: process to the next step
...
but when I'm checking compiled assembly I see the next code
static bool* lock;
...
bool lock_value = *lock;
while (lock_value);
// TODO: process to the next step
...
which means the thread will be stuck on the check cycle in the case initially *lock == false;
Question. Lets say this is not thread lock, it's some other thing: color, price etc. So how I can force check this pointer value. Of course, I can handle this by inline assembly
__asm {
lbl_back:
mov ecx, lock
mov eax, [ecx]
test eax, eax
jnz lbl_back
}
But how I can do this by C/C++ owns, without std and without external things? Just clear C/C++ language syntax
Thanks to all. volatile
is my choice