lectures.alex.balgavy.eu

Lecture notes from university.
git clone git://git.alex.balgavy.eu/lectures.alex.balgavy.eu.git
Log | Files | Refs | Submodules

Threads.html (4325B)


      1 <?xml version="1.0" encoding="UTF-8"?>
      2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      3 <html><head><link rel="stylesheet" href="sitewide.css"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><meta name="exporter-version" content="Evernote Mac 7.6 (457297)"/><meta name="altitude" content="-1.633376002311707"/><meta name="author" content="Alex Balgavy"/><meta name="created" content="2018-12-03 16:03:12 +0000"/><meta name="latitude" content="52.33331298828125"/><meta name="longitude" content="4.866615317820796"/><meta name="source" content="desktop.mac"/><meta name="updated" content="2018-12-14 15:44:59 +0000"/><title>Threads</title></head><body><div><b>multithreaded execution: 1 process, N threads of execution</b><br/></div><ul><li><div>lightweight processes, allow space and time efficient parallelism</div></li><li><div>organised in thread groups, allow simple communication and synchronisation</div></li></ul><div style="margin-top: 1em; margin-bottom: 1em; margin-left: 40px;-en-paragraph:true;"><img src="Threads.resources/4B0A8CCE-DB68-4C2A-AB82-391EC4A0720F.png" height="564" width="1172"/><br/></div><ul><li><div style="-en-paragraph:true;"><span style="-en-paragraph:true;">threads are in the same address space of a single process </span></div></li><li><div style="-en-paragraph:true;"><span style="-en-paragraph:true;">all info exchange done via data shared bet</span><span style="-en-paragraph:true;">ween threads </span></div></li><li><div style="-en-paragraph:true;"><span style="-en-paragraph:true;">threads synchronise via simple primitives </span></div></li><li><div style="-en-paragraph:true;"><span style="-en-paragraph:true;">each thread has its own stack, hardware registers, and state </span></div></li><li><div style="-en-paragraph:true;"><span style="-en-paragraph:true;">each thread may call any OS-supported syscall on behalf of the process to which it belongs</span></div></li></ul><div style="-en-paragraph:true;"><b><br/></b></div><div style="-en-paragraph:true;"><b>User threads - pros and cons</b><br/></div><ul><li><div>(+) thread switching time is quicker, as no mode switch</div></li><li><div>(+) scalability customizability (since no in-kernel management)</div></li><li><div>(-) parallelism (blocking syscalls are problematic)</div></li><li><div>(-) transparency (typically needs app cooperation)</div></li></ul><div style="margin-top: 1em;margin-bottom: 1em;-en-paragraph:true;"><img src="Threads.resources/59DC4D4C-51F2-4152-881F-46709D0B0FBE.png" height="264" width="600"/><br/></div><div><font face="Helvetica Neue"><b><br/></b></font></div><div><font face="Helvetica Neue"><b>Hybrid implementations of threads:</b></font></div><ul><li><div>thread multiplexing: one kernel thread runs everything</div></li><ul><li><div>virtualises N user threads over 1 kernel thread</div></li><li><div>mitigates transparency and parallelization issues</div></li></ul><li><div>scheduler activation: scheduler takes care of blocking/unblocking</div></li><ul><li><div>upcalls notify userland of blocking/unblocking events</div></li><li><div>userland schedules thread accordingly</div></li></ul><li><div>pop-up threads: kernel takes care of creating threads</div></li><ul><li><div>kernel spawns new thread in response to event</div></li><li><div>thread may run at kernel or user level</div></li></ul></ul><div><font face="Courier"><br/></font></div><div><font face="Helvetica Neue"><b>POSIX threads (Pthreads)</b></font></div><div><font face="Helvetica Neue">pthread is a library interface. names may not always be the same.</font></div><div style="margin-top: 1em;margin-bottom: 1em;-en-paragraph:true;"><img src="Threads.resources/0535A578-FC28-4B35-9C61-93A76C65980D.png" height="216" width="654"/><br/></div><div><font face="Helvetica Neue"><b>Inter-process communication (IPC)</b></font></div><ul><li><div>Processes need some way to communicate - to share data during execution</div></li><li><div>No explicit cross-process sharing, data must be normally exchanged between processes</div></li><li><div>Processes need a way to synchronise
      4 </div></li><ul><li><div>to account for dependencies</div></li><li><div>to avoid them interfering with each other</div></li></ul></ul><div><br/></div></body></html>