There's no need for M$ to implement pthreads, as there's already a
wrapper library for Win32, wrapping pthreads around Win32 threads. It's
called pthreads-win32.
If we want to add pthreads, or a direct copy-paste of pthreads spec to
the C spec, then Microsoft has to implement it, or we bifurcate the
language, and I think we can all agree that would be bad, or at best
neutral to what we have now. (I argue worse because then they might
start ignoring other aspects of the C standard. Gives them precedent,
now that they can never be fully conforming.) I suspect there would be
political pushback from Microsoft because of the names. If we can
avoid that political mess by simply adopting new names, I'm all for
that.
Could you elaborate or give pointers? Google didn't turn up anything
useful for the try_lock problem. Do you mean, that an application that
received a false on return of try_lock() doesn't know whether that was
just a temporary failure (aka Race Condition) or that an application
that constantly calls try_lock() won't be enqueued to the mutex the same
as an application that calls lock() is, leading to a situation where
constantly calling try_lock() results in an endless wait while lock()
would have succeeded by now?
Reordering Constraints for Pthread-Style Locks (2005)
by Hans-j. Boehm
http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.85.9908
The paper talks about a lot of things, including this issue. The
really short version is: Because the simple reading of
int pthread_mutex_trylock(pthread_mutex_t *mutex);
http://pubs.opengroup.org/onlinepubs/007904875/functions/pthread_mutex_lock.html
guarantees that pthread_mutex_trylock will acquire the mutex iff no
other thread currently has it, and thus pthread_mutex_trylock will
fail to acquire iff another thread currently has it, and the simple
rules of how threading without race conditions is basically
"expression" interleavings, then we can write some "interesting" code
that that assumes certain memory operations are visible in this thread
when trylock returns failure. However, as pthreads is commonly
implemented, this is very not true.
C++11 and C1x fix this by allowing trylock to fail spuriously (and
properly documenting the acquire and release semantics of
acquire_mutex and release_mutex). When trylock returns failure in C+
+11 / C1x, this gives you no useful information; another thread may
have the mutex, and it's possible currently no thread has the mutex.
In practice, it won't be implemented to randomly fail, but the formal
specification of allowing spurious failures (along with properly
documenting acquire and release semantics) remove these troublesome
executions which abuse trylock.