<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2019W_Lecture_17</id>
	<title>Operating Systems 2019W Lecture 17 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2019W_Lecture_17"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2019W_Lecture_17&amp;action=history"/>
	<updated>2026-04-05T17:00:48Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2019W_Lecture_17&amp;diff=22280&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  Video for the lecture given on March 18, 2019 [https://homeostasis.scs.carleton.ca/~soma/os-2019w/lectures/comp3000-2019w-lec17-20190318.m4v is now available].  ==N...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2019W_Lecture_17&amp;diff=22280&amp;oldid=prev"/>
		<updated>2019-03-18T22:30:00Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  Video for the lecture given on March 18, 2019 [https://homeostasis.scs.carleton.ca/~soma/os-2019w/lectures/comp3000-2019w-lec17-20190318.m4v is now available].  ==N...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video for the lecture given on March 18, 2019 [https://homeostasis.scs.carleton.ca/~soma/os-2019w/lectures/comp3000-2019w-lec17-20190318.m4v is now available].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 17&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
Wednesday will be &amp;quot;online&amp;quot; (likely)&lt;br /&gt;
&lt;br /&gt;
Concurrency&lt;br /&gt;
-----------&lt;br /&gt;
&lt;br /&gt;
First, asynchronous programming (e.g., node)&lt;br /&gt;
 - non-blocking I/O&lt;br /&gt;
   - so, you use callbacks to continue after long operations (such as I/O)&lt;br /&gt;
 - in node, is done in a single-threaded application&lt;br /&gt;
   - execution is purely sequential, never parallel (in the program)&lt;br /&gt;
&lt;br /&gt;
Concurrent programming is when you have parallel executions that can interact&lt;br /&gt;
 - processes running on separate data, not communicating are NOT concurrent&lt;br /&gt;
 - but once they communicate or share resources, they are concurrent&lt;br /&gt;
&lt;br /&gt;
Concurrent programming is hard because the relative speed of programs determines how the system behaves&lt;br /&gt;
 - A faster than B != B faster than A&lt;br /&gt;
&lt;br /&gt;
Relational databases were developed to manage concurrent access to data&lt;br /&gt;
&lt;br /&gt;
Regular applications should normally use databases to manage concurrent access to data.  But the operating system can&amp;#039;t (because databases depend on the OS!)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Transactions are a way of making sets of non-atomic operations atomic&lt;br /&gt;
 - atomic =&amp;gt; indivisible&lt;br /&gt;
&lt;br /&gt;
How do you make something that is divisible, indivisible?&lt;br /&gt;
 - all operations succeed or none of them do&lt;br /&gt;
   - if anything fails in the middle, undo the rest&lt;br /&gt;
&lt;br /&gt;
Airline reservations&lt;br /&gt;
 - reserve a seat  (seat map)&lt;br /&gt;
 - pay for the seat (payments)&lt;br /&gt;
 - get customer information (customers)&lt;br /&gt;
&lt;br /&gt;
Think of these as three tables&lt;br /&gt;
&lt;br /&gt;
A transaction allows us to either update all three tables or none of the tables&lt;br /&gt;
 - cancel a transaction, and all parts of it are undone as if they never happened&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the kernel, we can&amp;#039;t use ready-made transactions, but we simulate them all the time when we allocate resources&lt;br /&gt;
 - we don&amp;#039;t want to get into weird states were only some of the resources have been allocated.  That&amp;#039;s how you get memory leaks or worse.&lt;br /&gt;
 - most common resources we wish to access are data structures&lt;br /&gt;
&lt;br /&gt;
To mediate access to data structures, we use locks&lt;br /&gt;
&lt;br /&gt;
A lock is just a means of enforcing exclusive access of some kind&lt;br /&gt;
 - can treat reads and writes differently&lt;br /&gt;
&lt;br /&gt;
Files can have advisory or mandatory locks&lt;br /&gt;
 - can you bypass the lock or not&lt;br /&gt;
&lt;br /&gt;
For in-memory data structures, all locks are advisory&lt;br /&gt;
 - which makes them painful to debug&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Classic locks are semaphores, specifically mutexes&lt;br /&gt;
 - a mutex is a binary semaphore (semaphore with a value of 0 or 1)&lt;br /&gt;
&lt;br /&gt;
If you try to get it (down on a mutex), if it succeeds, you own the lock&lt;br /&gt;
If you don&amp;#039;t get it, you wait until it is free (blocking)&lt;br /&gt;
If you don&amp;#039;t get it, lock attempt fails (non-blocking)&lt;br /&gt;
&lt;br /&gt;
If you block, you can either&lt;br /&gt;
 - busy wait (for in-memory data structures)&lt;br /&gt;
 - sleep (for I/O)&lt;br /&gt;
&lt;br /&gt;
Your code should hold onto locks for as little time as possible&lt;br /&gt;
&lt;br /&gt;
A critical section is the part of your code that interacts with the shared resource.  This is the part that should be protected by a lock.&lt;br /&gt;
 - critical sections should be short&lt;br /&gt;
 - they should release locks always&lt;br /&gt;
&lt;br /&gt;
deadlock&lt;br /&gt;
 - parts of system can never get resources they need because they are held by another part of the system&lt;br /&gt;
 - Alice has a fork, Bob has a knife, but both Alice and Bob need a fork and knife to eat their food.&lt;br /&gt;
 - participants in a deadlock &amp;quot;starve&amp;quot;&lt;br /&gt;
&lt;br /&gt;
How to resolve deadlock?&lt;br /&gt;
 - timeouts&lt;br /&gt;
 - kill someone&lt;br /&gt;
    - doesn&amp;#039;t work in the kernel&lt;br /&gt;
 - start over&lt;br /&gt;
    - reboot&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>