Single computing node, multiple sockets, multiple cores.
1
- Intel Sandy Bridge CPU.
pthreads specifies the interface of using threads, but not how threads are implemented in OS.Launch your csc466env environment and go to 127.0.0.1:18088
1
docker compose up -d head
Click on the top-left three dashes, select File then Open Folder
/home/student in the box then press OK
thread_hello.c with the following contents:```c linenums=”1” –8<– “docs/csc466/lectures/data/thread/hello_thread.c”
1
2
3
4
5
6
7
8
- Compile and run `thread_hello.c`:
```bash
gcc -o thread_hello thread_hello.c -lpthread
./thread_hello 1
./thread_hello 2
./thread_hello 4
thread_sum.c with the following contents:```c linenums=”1” –8<– “docs/csc466/lectures/data/thread/thread_sum.c”
1
2
3
4
5
6
7
8
- Compile and run `thread_sum.c`:
```bash
gcc -o thread_sum thread_sum.c -lpthread
./thread_sum 16 4
./thread_sum 256 4
./thread_sum 1000000 4
thread_global_nolock.c with the following contents:```c linenums=”1” –8<– “docs/csc466/lectures/data/thread/thread_global_nolock.c”
1
2
3
4
5
6
7
8
9
10
- Compile and run `thread_global_nolock.c`:
- Compare the outcome with `thread_sum`
```bash
gcc -o thread_global_nolock thread_global_nolock.c -lpthread
./thread_global_nolock 16 4
./thread_global_nolock 2000 4
./thread_global_nolock 90000 4
./thread_sum 90000 4
sum variable) without any synchronization.
Mutual Exclusion: if one thread is in the CS, then no other isProgress: threads waiting for access to CS are not prevented from entering by threads not in the CS; threads do not wait indefinitely.Bounded Waiting (no starvation): all waiting threads are guaranteed to eventually get access to the CS.Performance: The overhead of entering and exiting the CS is small compared to the work done within it.Atomic instruction: A machine instruction that can be executed in a single clock cycle.lock() when it tries to acquire the lock: pthread: https://linux.die.net/man/3/pthread_mutex_lockthread_global_lock.c with the following contents:```c linenums=”1” –8<– “docs/csc466/lectures/data/thread/thread_global_lock.c”
1
2
3
4
5
6
7
8
9
10
11
12
13
- Compile and run `thread_global_lock.c`:
- Compare the outcome with `thread_sum`
- Compare the runtime with `thread_sum` and `thread_global_nolock` with a lower input value
```bash
gcc -o thread_global_lock thread_global_lock.c -lpthread
./thread_global_lock 90000 4
./thread_global_nolock 90000 4
./thread_sum 90000 4
./thread_global_lock 2000 4
./thread_global_nolock 2000 4
./thread_sum 2000 4