Let's dive into CThreads Interface aka POSIX Threads
which isn't shipped natively with C, it's based on Unix :
https://www.ibm.com/docs/en/zos/2.4.0?topic=files-pthreadh-thread-interfaces
https://www.ibm.com/docs/en/i/7.1?topic=ssw_ibm_i_71/apis/concept8.htm
https://www.geeksforgeeks.org/thread-functions-in-c-c/
https://www.ibm.com/docs/en/zos/2.3.0?topic=functions-pthread-mutex-init-initialize-mutex-object
#include <bits/types/struct_timespec.h>
/* Wait until lock becomes available, or specified time passes. */
extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex,
const struct timespec *__restrict__abstime);
/* NB: Include guard matches what <linux/time.h> uses. */
#ifndef _STRUCT_TIMESPEC
#define _STRUCT_TIMESPEC 1
#include <bits/types.h>
#include <bits/endian.h>
/* POSIX.1b structure for a time value. This is like a `struct timeval' but
has nanoseconds instead of microseconds. */
struct timespec
{
__time_t tv_sec; /* Seconds. */
#if __WORDSIZE == 64 \
|| (defined __SYSCALL_WORDSIZE && __SYSCALL_WORDSIZE == 64) \
|| __TIMESIZE == 32
__syscall_slong_t tv_nsec; /* Nanoseconds. */
#else
# if __BYTE_ORDER == __BIG_ENDIAN
int: 32; /* Padding. */
long int tv_nsec; /* Nanoseconds. */
# else
long int tv_nsec; /* Nanoseconds. */
int: 32; /* Padding. */
# endif
#endif
};
#endif
https://en.cppreference.com/w/c/chrono/timespec
┌─[twisted@parrot]─[~/GradleProjects/CThreads/build]
└──╼ $./compile.sh
Compiling the project
Successfully Compiled
┌─[twisted@parrot]─[~/GradleProjects/CThreads/output]
└──╼ $./ThreadsTest.exec
Main Thread joined
Async 2 joined
139843706689280 Aysnc 2 Terminated
Thread 1
Async 1 joined
139843715081984 Aysnc 1 Terminated
139843698296576 (Thread 1) has been detached & terminated
Thread 2
139843698296576 (Thread 2) has been detached & terminated
mutex_initialized & property settled to NORMAL single lock mutually events
mutex object obtained by Event 1 -- Event 1 execution starts
mutex_locked to this Event 1, concurrent threads will wait until unlock occurs
mutex object obtained by Event 2 -- Event 2 execution starts
mutex_locked to this Event 2, concurrent threads will wait until unlock occurs