|
|
On Jul 18, 7:01 am, Paul Pluzhnikov <ppluzhnikov-...@xxxxxxxxx> wrote:
> mynickmynick <mynickmyn...@xxxxxxxxx> writes:
> > if a variable is inside lock/unlock then it cannot be taken from a
> > previous cache and/or register
> > but are compiler so "smart"
> > that is : is pthread_mutex_lock part of C language or not (function
> > like any other?) ??
>
> I don't get you. Several people have already answered your questions,
> but you keep asking the same questions over and over :(
>
> For most compilers, pthread_mutex_lock is a function *just* like
> any other. A compiler can not keep a global variable in a register
> across a call to *any* function, for which it has not seen the
> source, and pthread_mutex_lock is one such function.
>
> > It seems to me there is quite confusion around this topic
>
> Yes, you appear to be confused, despite everybody's best effors :(
>
> Cheers,
> --
> In order to understand recursion you must first understand recursion.
> Remove /-nsp/ for email.
now I think I got it
in my example
[code]
Thread1
..
while(quit) {do things without using quit}
..
Thread 2
..
quit++;
..
Correction2
Thread1
..
..lock..
quitV=quit;
..unlock..
while(quitV)
{
do things without using quit
..lock..
quitV=quit;
..unlock..
}
..
Thread 2
..
..lock..
quit++;
..unlock..
..
[/code]
In "Correction 2"
there is a sort of side (good) effect in compiling:
as quit is a global variable
and as pthread_mutex_lock(&mutex); is opaque to the compiler (so it
might change quit value)
the compiler thinks it cannot keep quit on a register so loads quit
form memory at every while iteration
while without correction and if
"{do things without using quit} "
has no function call
the compiler might decide to keep the quit value on a register, so
deadlocking!
is that right?
thank you for support
|
|