Comments (7)
According to the C11 standard, the correct solution would be for client code to look like this:
#ifdef __STDC_NO_THREADS__
#include "c11threads.h" // Use home-grown substitute
#else
# include <threads.h> // Use standard libc header
#endif
No need to change c11threads.h
.
from c11threads.
Not a bad idea, but is there any libc out there which supports C11 threads to test against?
from c11threads.
http://stackoverflow.com/questions/24557728/does-any-c-library-implement-c11-threads-for-gnu-linux
You could try musl.
The latest glibc at least sets __STDC_NO_THREADS__
to 1
. Previous versions don't, sigh -.-
from c11threads.
But if you use musl with c11 threads, why would you include this c11thread.h file ?
from c11threads.
Thats the point of this issue: Only include c11thread.h
in case your libc does not have C11 thread support.
from c11threads.
You are right.
from c11threads.
The correct way to check for C standard library support for threads at compile time should be
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_THREADS__)
#include <threads.h>
#else
#include "c11threads.h"
#endif
A possible solution to automatically use the standard library if available could be to add these lines to c11threads.h, replacing #include "c11threads.h"
with the current content of the header.
Note that nowadays all distributions are shipped with a version of glibc supporting threads.
from c11threads.
Related Issues (14)
- thrd_detach is spelled incorrectly HOT 1
- gcc timespec_get build error HOT 2
- Trap deadlocks
- thrd_sleep should return int HOT 1
- warning: cast to pointer from integer HOT 6
- Duplicated declaration of timespec_get() on MacOSX HOT 2
- error: weak declaration of 'thrd_exit' must be public HOT 2
- <stdint.h> HOT 3
- C11THREADS_TIMEDLOCK_POLL_INTERVAL not defined HOT 1
- Test failure on FreeBSD HOT 5
- Windows threads support HOT 8
- CI HOT 1
- PTHREAD_MUTEX_TIMED_NP Isn't available outside of linux. HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from c11threads.