Professional Documents
Culture Documents
C Thread.
C Thread.
C Thread.
Threads
Instructor: Yin Lou
02/16/2011
Introduction to C
Processes
Threads
Multiple simultaneous
programs
Multiple simultaneous
functions
Independent open
file-descriptors
Introduction to C
Threads Examples
Introduction to C
Threads
Multiple stacks
Introduction to C
Threads
Multiple stacks
Life Cycle
Introduction to C
pthread
#include <pthread.h>
Introduction to C
pthread
I
I
#include <pthread.h>
Define a worker function
Introduction to C
pthread
I
I
#include <pthread.h>
Define a worker function
I
Introduction to C
pthread
I
I
#include <pthread.h>
Define a worker function
I
Introduction to C
pthread
I
I
#include <pthread.h>
Define a worker function
I
Introduction to C
pthread
I
I
#include <pthread.h>
Define a worker function
I
Create a thread
Introduction to C
pthread
I
I
#include <pthread.h>
Define a worker function
I
Create a thread
I
I
pthread t thread;
pthread create(&thread, &attr, worker function, arg);
Introduction to C
pthread
I
I
#include <pthread.h>
Define a worker function
I
Create a thread
I
I
pthread t thread;
pthread create(&thread, &attr, worker function, arg);
Introduction to C
pthread
I
I
#include <pthread.h>
Define a worker function
I
Create a thread
I
I
pthread t thread;
pthread create(&thread, &attr, worker function, arg);
pthread exit(status)
Introduction to C
Example
#include <stdio.h>
#include <pthread.h>
#define NUM_THREADS
Introduction to C
Thread Management
pthread detach(threadid)
Introduction to C
Example
#include <stdio.h>
#include <pthread.h>
#define NUM_THREADS
Introduction to C
Compiling
I
Use -pthread
Introduction to C
Compiling
I
Use -pthread
Makefile
CC:=gcc
OPTIONS:=-O2
LIB_PATH:=-pthread
SRC_DIR:=src
DST_DIR:=bin
default:
$(CC) $(OPTIONS) $(LIB_PATH) \
$(SRC_DIR)/*.c -o $(DST_DIR)/test
clean:
cd $(DST_DIR); rm test
Introduction to C