0%

NTHU-Operating System: Chap4 Multithreaded Programming

Overview

Thread Introduction

Threads

Motivation

Benefits of Multithreading

Why Thread?

Multithcore Programming

Challenges in Multicore Programming

User vs. Kernel Threads


Multithreading Models

Many-to-One

One-to-one

Many-to-Many

Threaded Case Study

Case Study

Shared-Memory Programming

What is Pthread?

Pthread Creation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <pthread.h>
#include <stdio.h>
#define NUM_THREADS 5

void *PrintHello(void *threadld) {
long *data = (long *) threadld;
printf("Hello World! tid = %ld\n", *data);
pthread_exit(NULL);
}

int main() {
pthread_t threads[NUM_THREADS];
for(long tid = 0; tid < NUM_THREADS; tid++) {
pthread_create(&threads[tid], NULL, PrintHello, (void *)&tid);
}
pthread_exit(NULL);

return 0;
}

Pthread Joining & Detaching

Java Threads

Linux Threads


Threading Issues

Semantics of fork() and exec()

Thread Cancellation

Signal Handling

Thread Pools

求大佬赏个饭