Re: Mutex/Lock
On May 31, 12:20 pm, Chris Forone <4...@gmx.at> wrote:
James Kanze schrieb:
[...]
Thanx for the example. The wait is done with the win32 function
WaitForSingleObject() with no timeout.
That is, I think, a join.
Windows is noted for using non-standard terminology, although in
this case, it might be justified. Still, if there is a function
which will insist that the handle refers to a thread, and return
an error if it doesn't, I'd use that. Static typing is
significantly more robust than dynamic typing.
Excuse me for the incomplete example:
bool Exit()
{
mutex.Acquire();
if (active)
{
active = false;
mutex.Release();
return WaitForSingleObject(thread, INFINITE) == WAIT_OBJECT_0;
}
mutex.Release();
This call will fail (probably with an assertion failure, if the
Mutex class is well written) if the condition for the if is
true.
}
The side effect-thing i dont understand...
What about:
return someVar1 == 10 &&
someVar2 != 20 &&
(someVar3 = someFunc()) == true;
&& and || are also sequence points. But I'd never write code
like that, with a change of state hidden down in the middle of a
complicated expression, where it won't be easily seen. Nor
would I compare with true: if someVar3 has type bool, then
that's what you need, and no comparison is necessary, and if it
doesn't, I'd write the comparison to compare with something of
whatever type it has.
and
return (someVar1 == 10) &&
(someVar2 != 20) &&
(someVar3 = someFunc()) == true;
Parentheses don't change anything.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34