Tutorial by Examples

Detailed instructions on getting pthreads set up or installed.
#include <pthread.h> #include <stdio.h> #include <string.h> /* function to be run as a thread always must have the same signature: it has one void* parameter and returns void */ void *threadfunction(void *arg) { printf("Hello, World!\n"); /*printf() is speci...
#include <stdio.h> #include <pthread.h> void *thread_func(void *arg) { printf("I am thread #%d\n", *(int *)arg); return NULL; } int main(int argc, char *argv[]) { pthread_t t1, t2; int i = 1; int j = 2; /* Create 2 threads t1 and t2 wit...
A pointer to a concrete data type, converted to void *, can be used to pass values to and return results from the thread function. #include <stdio.h> #include <stdlib.h> #include <pthread.h> struct thread_args { int a; double b; }; struct thread_result { ...

Page 1 of 1