Lesson 40 of 50
cMultithreading with `<threads.h>` (C11)
15 mins
Course progress80%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 40 of 50
c15 mins
Keep these ideas in mind as you work through the lesson.
C11 introduced a portable threading API: thrd_t, mtx_t, cnd_t etc., from <threads.h>.
Typical workflow:
thrd_create(&t, func, arg);.thrd_join(t, &ret);.mtx_lock, mtx_unlock).mtx_t lock;
mtx_init(&lock, mtx_plain);
mtx_lock(&lock);
/* critical section */
mtx_unlock(&lock);
The API is intentionally minimal – for more advanced needs use POSIX threads (pthread) on Unix or Win32 threads on Windows.