pthread_mutex: move in from cpp-cheat

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-11-19 00:00:00 +00:00
parent 9dfcb316bf
commit 5fd2a3da76
3 changed files with 78 additions and 1 deletions

View File

@@ -13674,6 +13674,11 @@ time ./std_atomic.out 4 100000000
time ./mutex.out 4 100000000
....
Related examples:
* POSIX <<pthread-mutex>>
* C11 link:userland/c/atomic.c[] documented at <<c-multithreading>>
Bibliography:
* https://stackoverflow.com/questions/31978324/what-exactly-is-stdatomic/58904448#58904448 "What exactly is std::atomic?"
@@ -13754,6 +13759,23 @@ This was for a looong time the only "portable" multithreading alternative, until
* link:userland/posix/pthread_deadlock.c[]
* link:userland/posix/pthread_self.c[]
[[pthread-mutex]]
===== pthread_mutex
link:userland/posix/pthread_count.c[] exemplifies the functions:
* `pthread_mutex_lock`
* pthread_mutex_unlock
That example that the same interface as: <<atomic-cpp>>.
There are no non-locking atomic types or atomic primitives in POSIX: http://stackoverflow.com/questions/1130018/unix-portable-atomic-operations
`pthread_mutex_lock` and `pthread_mutex_unlock` and many other pthread functions already enforce cross thread memory synchronization:
* https://stackoverflow.com/questions/78172/using-c-pthreads-do-shared-variables-need-to-be-volatile/58935671#58935671
* https://stackoverflow.com/questions/3208060/does-guarding-a-variable-with-a-pthread-mutex-guarantee-its-also-not-cached
* https://stackoverflow.com/questions/24137964/does-pthread-mutex-lock-contains-memory-fence-instruction
==== sysconf
https://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html
@@ -13937,7 +13959,7 @@ It is also possible to the algorithm tests normally from emulators in <<user-mod
Sources:
* link:userland/algorithm/set/generate_input[]
* link:userland/algorithm/set/generate_io[]
* link:userland/algorithm/set/main.hpp[]
* link:userland/algorithm/set/parse_output[]
* link:userland/algorithm/set/std_set.cpp[]