程序代写 COMP 3430 Operating systems

COMP 3430 Operating systems
Threads intro

February 2nd, 2022

Copyright By PowCoder代写 加微信 powcoder

By the end of today’s lecture, you should be able to:
▶ Compare and contrast processes and threads.
▶ Write a simple program that creates and runs threads.
The Rocket Book (Public Domain)

Loom (Pixabay License)
▶ Processes → coarse-grained concurrency
▶ Easier to use (fork off and forget)
▶ Everything** is copied (see: man 2
▶ Threads → fine-grained concurrency
▶ Harder to use (we have to manage threads)
▶ Cheaper to use (memory is shared) ( ?)

Why use threads?
why (Pixabay License)

▶ How much do threads cost to create?
▶ Let’s do a poll
▶ Let’s take a measurement .
Cash money ( ©Bank of Canada – Banque du Canada)

Threads are not free
A lot more cash money ( ©Bank of Canada – Banque du Canada)
▶ Threads are cheap – compared to processes
▶ Think about it: When/what/where is the cost(s) with threads?
▶ Think a bit more: Can we reduce these costs?

It’s a pool of water ( ©rivalius13 CC BY-NC-SA 2.0)
▶ Idea: Amortize the costs
▶ Try to minimize cost of creation over
work done.
▶ Create many threads when the program
▶ Hand out already created threads when
work needs to be done.

▶ COMP 3350: Thread pools are a design pattern.
▶ More generally: Resource pools (connections, handles, etc)
▶ Let’s look at some code.

▶ Threads are a more granular form of concurrency. ▶ Threads are cheaper than processes, but not free.
▶ We can improve threading performance using resource pools.

An interface! ( ©Pittigrilli and Zinnmann CC BY-SA 4.0)
Starting from thr_pool.h: What is in the interface of this thread pool? Specifically: what operations does the thread pool provide in terms of manipulating threads and in terms of manipulating a thread pool?

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com