Thread Creation

#include <pthread.h>
int
	pthread_create(
									pthread_t *thread,
									const pthread_attr_t *attr,
									void *(*start_routine)(void*),
									void *arg
								);

The pthread_create api is defined above and it accepts the following args:

Thread Completion

int pthread_join(pthread_t thread, void **value_ptr);

pass in a thread and retrieve the value in value_ptr, basically equal to

res = await execute(thread)
value_ptr = &res

Locks

int pthread_mutex_lock(pthread_mutex_t *mutex);
int pthread_mutex_unlock(pthread_mutex_t *mutex);

when you have a critical section, you can do

pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
pthred_mutex_lock(&lock);
// critical section goes here...
pthread_mutex_unlock(&lock);

Or to initialize the lock dynamically, we can do

int rc = pthread_mutex_init(&lock, NULL)
assert(rc == 0);