DEV Community

Discussion on: Basics of multithreading in C

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y

pthread is outdated since availability of C11 which introduced standard threading in C. The header files is <threads.h> with functions like thrd_create.

The standard functions for threading, conditions, and signalling, provide guarantees that pthreads cannot.

Collapse
 
quantumsheep profile image
Nathanael Demacon

pthread.h is POSIX compliant, threads.h isn't.

But sure you can use it, it's implemented in linux and freeBSD kernels.

Collapse
 
noah11012 profile image
Noah11012

But threads.h is C11 compliant so by now ALL compilers have support for C11 at least for the three major ones:

MSVC
GCC
CLANG

Thread Thread
 
quantumsheep profile image
Nathanael Demacon

Yup, seems nice, their is just a lack of documentation, I wanted to know what did it really does.

Thread Thread
 
noah11012 profile image
Noah11012

You can find documentation here: en.cppreference.com/w/c/thread

Thread Thread
 
jl2210 profile image
JL2210

Well, it's the C libraries for two of those platforms that are supposed to implement threads.h (even though I'm pretty sure glibc doesn't), although I'm not sure what Windows does.

Collapse
 
jl2210 profile image
JL2210

It's not the kernels, it's the C libraries. You can have a kernel installed and not be able to do anything without a C library.

Collapse
 
quantumsheep profile image
Nathanael Demacon

I have my answers, threads.h is better to use even if it's not POSIX (stackoverflow.com/a/9377007)