[cpp-threads] Somewhat relevant technical report
Nick Maclaren
nmm1 at cus.cam.ac.uk
Sat Dec 17 15:57:44 GMT 2005
> > As I see it, the only reason this might not be guaranteed is that
> > pthread_mutex_try_lock doesn't guarantee memory synchronization in
> > this case.
> >
> > It's unclear what that statement means.
>
> To me it means exactly what it says. A failed pthread_mutex_trylock is a
> no-op with respect to memory synchronization and visibility, a { return
> false; }.
Sigh. No, it CLEARLY doesn't mean that.
It says that it is UNSPECIFIED, which is not the same as saying that
it is a null operation. I agree that it means that memory MAY NOT
be synchronised - i.e. it MAY be implemented as:
Synchronise state of mutex
Attempt to get mutex
Return if failed
Synchronise memory
Return
But it need not be. It could be implemented as:
Synchronise memory
Attempt to get mutex
Return
HOWEVER, Hans is right. The pthread_mutex_lock did succeed (so memory
is synchronised), and the pthread_mutex_trylock is then temporarily
ordered with respect to that (because it fails). Like Hans, I have
no idea what POSIX means - but, unlike him, I doubt that there is even
a consistent intent behind the specification.
I described some of the issues in a previous posting - the one that
referred to global, transitive or pairwise synchronisation - and that
posting is very relevant here. Until and unless we can agree on the
basics of the model, there will be an indefinite stream of such, er,
cross-purpose debates.
Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email: nmm1 at cam.ac.uk
Tel.: +44 1223 334761 Fax: +44 1223 334679
More information about the cpp-threads
mailing list