Download SOFT3410 Final Exam Questions and Solutions: Concurrency and Operating Systems and more Exams Computer Science in PDF only on Docsity!
Questions and Solutions.
What are polymorphic transactions? - Correct Ans: It provides multiple forms of transactions:
- Hand-over-hand (elastic opacity semantics, ensures atomicity of consecutive accesses)
- Snapshot transactions (atomic snapshot semantic, uses multi-version concurrency control)
- Irrevocable (can be used for irrevocable actions, uses a global reader-writer lock to disallow other transactions from running concurrently)
- Opaque transactions (opacity semantics, appears as if read/write sequences executed atomically Polymorphic Transaction makes concurrent programming reusable (simple) and efficient What is Pollack's Law? - Correct Ans: Better performance results in higher energy consumption What are hot spots? - Correct Ans: Code regions in the application that consume a lot of CPU time. Tree rotations produce contention How do you remove hot spots? - Correct Ans:
- Relaxing invariants (e.g. balanced trees) in case of contention bursts
- Re-ensuring invariant in the absence of contention What is a Skip list - Correct Ans: A data structure that allows O(logn) average search and insertion complexity within an ordered sequence of elements. They are appealing for in-memory databases Hotspots are at the top of the structure towers
Questions and Solutions.
How do you do the no hot spot skip list? - Correct Ans: Key idea: update decoupling into two stages:
- Eager abstract modification: returns quickly and whose update affects only the bottom of the structure
- Lazy and selective adaptation: postpone the adaptation at higher levels (update), chooses the least likely contended towers (remove). Updating potentially the entire structure but executed continuously in the background (garbage collection, physically remove logically deleted nodes) What are the three steps in Speculation-Friendly Trees? What is the algorithm overview? What are some more optimisations? - Correct Ans:
- Rotation decoupling
- Deletion decoupling
- Further optimisations Algorithm overview: we now know the height of both subtrees
- One thread continuously propagates and rotates
- few conflicts (node-local transactional rotations)
- under contention means unbalanced tree
- without contention means eventually balanced tree
- No removal of nodes with two children
- the tree does not seem to grow much in practice Further optimisations
- Lightweight reads => elastic transactions
- Conflict-free rotations => no backtrack on removal, rather postpone
- STAMP vacation HTM vs STM - Correct Ans:
Questions and Solutions.
- Don't forget to list experimental settings What kinds of things do you backup for experiments? - Correct Ans:
- keep output logs (can be used for mean/median/min)
- aggregate (keep intermediary data)
- visualise (keep visualisation script) also use version management To create or not to create benchmarks? - Correct Ans: Take existing benchmarks
- Do not reinvent the wheel
- List the parameters
- Explain the experimental settings How do you compare-and-set two values atomically? - Correct Ans: Java AtomicMarkableReference stores the mark and reference separately, requiring an extra read to return the reference Bitmask in C/C++ What if the initial size (parameter i) is larger than the value range (parameter r)? - Correct Ans: The benchmark may never start collecting statistics. Why does the warmup parameter of Synchrobench do? - Correct Ans: It waits some delay to let the JVM optimize if necessary before collecting statistics. How to keep the size of this data structure constant in expectation during a Synchrobench execution? - Correct Ans: By setting the range twice as large as the initial size.
Questions and Solutions.
What is the Traditional Uniprocessor? - Correct Ans: Single CPU, single memory What is Moore's Law? - Correct Ans: # of transistors per chip doubles every two years. Problem is that performance no longer increases with # transistors What is the symmetric multi-processor (SMP)? - Correct Ans: The processing of programs by multiple processors that share a common operating system and memory What is the chip multi-processor (CMP) (multicore)? - Correct Ans: Computer processor integrated circuit with two or more separate processing units (cores), each of which reads and executes program instructions Amdahl's Law Formula - Correct Ans: Speed = oldtime / newtime Speedup = 1 / (1-p+(p/n)) p = parallel fraction n = number of processors What are some ways to parallelise code? - Correct Ans:
- Minimising the sequential parts
- Reducing idle time in which threads wait What is a batch in terms of the OS? - Correct Ans: One execution at a time What is uniprogramming? - Correct Ans: One program execution at a time (e.g. MS/DOS, early macintosh, batch processing) What is multiprogramming? - Correct Ans: Multiple program executions simultaneously (e.g. UNIX/linux, Windows NT, Mac OS X)
Questions and Solutions.
In terms of process creation, what is the process allocation and execution environment? - Correct Ans: Allocation: the act of choosing the host of the process Environment: address space w/ initialised content and open files
- static: program txt, stack regions
- dynamic: fork shares program text and copies stack and heap regions What/how is Interprocess Communication (IPC) - Correct Ans: Pipes/Message Queues/Shared memory segments Requires costly context switches What is a Context-Switch? - Correct Ans: An interrupt that requires kernel intervention
- Process A switches from user to kernel mode (change memory map in MMU, flush TLB)
- Context-switch (swap processes from disk to main memory)
- Process B switches from kernel to user mode What is a thread (i.e. POSIX) and how is communication done? - Correct Ans: Smallest unit of CPU utilisation POSIX: Portable OS Interface, it defines the API Communication is done through memory (no need for IPC or context switch) What are some traits about user-level thread library? - Correct Ans: Cheap to create and destroy Blocking system call freezes the entire process of the thread Cheap context-switches (few instruction to store and reload CPU register values, no need to change memory map in MMU or flush the TLB) What are some traits about kernel-level thread library? - Correct Ans: Costly to create and destroy
Questions and Solutions.
Do not block the current process upon blocking system calls Costly context switch (needs to change memory map in MMU and flush the TLB) What are lightweight processes (LWP)? - Correct Ans: LWPs are a means of achieving multitasking. They run in user space on top of a single kernel thread and shares its address space and system resources with other LWPs within the same process Slower and more expensive than user threads because when they are created a system call to create a kernel thread as they are managed by the kernel, requiring a switch to kernel mode What are the steps for LWPs? - Correct Ans: 1. Runs in the context of a process
- Current threads are in a table
- Once an LWP finds a runnable thread: it locks the table in user-mode to update it, and it switches context to that thread in user-mode
- Does not block upon system calls: passing from user to kernel in LWP context, if LWP is blocked, the kernel context-switches to another LWP, implying context-switch also at user level What is the main differences between processes and threads? - Correct Ans: Processes: isolated, inefficient Threads: non-isolated, efficient
- generally faster than a process, however, it shares data with other threads What is a JVM thread? - Correct Ans: JVM Thread: main thread, responsible for executing VM operations (1) implements the runnable interface (2) allocate a new thread (3) start it
Questions and Solutions.
Thread pool: creates pool of threads that the server can reuse, no need to initialise many threads, nor to destroy many threads Other alternatives:
- single-threaded: one loop iteration must treat request before starting to treat another (requests lost)
- finite state machine: uses cache What are characteristics of threads, single-threaded process, and finite-state machine? - Correct Ans: Threads: parallelism, blocking system calls Single-threaded processes: no parallelism, blocking system calls Finite-state machine: parallelism, nonblocking system calls What are short, long and really long delays when dealing with asynchrony? - Correct Ans: Short: cache misses Long: page faults Really long: scheduling quantum used up What is load balancing? - Correct Ans: Splitting the work evenly. A way of routing client requests across all servers in a manner that maximises speed and capacity utilisation and ensures no one server is overworked, which could degrade performance What is the prime number parallel problem? - Correct Ans: Print primes from 1 to 10^10, given 10 processors and get 10-fold speedup. Problems are that higher numbers have fewer prime numbers, larger numbers are harder to test. Need dynamic load balancing What are the two properties in asynchronous computation? - Correct Ans: Safety - nothing bad happens ever (mutual exclusion) Liveness - something good happens eventually (no deadlocks)
Questions and Solutions.
Principles and Ponds and Dragons - Correct Ans: Please see mutual exclusion lecture What is a mutex? - Correct Ans: A program object that prevents simultaneous access to a shared resource. Only one thread has the mutex at a time, when a thread holds a resource, it needs to lock the mutex from other threads How can/cannot mutual exclusion be solved? - Correct Ans: Cannot - transient communication, interrupts Can - one-bit shared variables that can be read or written What is a deadlock? - Correct Ans: A situation where two or more processes are waiting for the other to finish and release their resources (all processes in the waiting state)
- Multiple locks acquired in arbitrary order may lead to deadlock
- Multiple locks acquired in a single shared order are safe from deadlock (lexical, memory address)
- A deadlock leads to starvation
- A deadlock violates liveness (not safety) What is a livelock? - Correct Ans: This occurs when two or more processes continually repeat the same interaction in response to changes in the other processes without doing any useful work. This leads to starvation What is starvation? - Correct Ans: This problem occurs when a process is perpetually denied necessary access to resources to process its work
Questions and Solutions.
Allows the system to always make progress CAS helps boosting performance, except for trees. Also difficult to use efficiently What is contention-friendliness? - Correct Ans: Pb: the growing core count induces contention Idea: relax structural invariants during load bursts (level distribution, depth, load factor) Minimise contention, postpone restructuring How: Speculation-Friendly Tree, Contention-Friendly Hash Table, No Hot Spot Skip List, Contention-Friendly Tree, Rotating Skip List, Chromatic Tree, Logical Ordering Tree What is Read-copy-update (RCU)? - Correct Ans: Allows multiple threads to efficiently read from shared memory by deferring updates after pre-existing reads to a later time while simultaneously marking the data, ensuring new readers will read the updated data Readers proceed uninterrupted, writers copy the data to be modified Good for read-only execution, terrible under contention (worse than TM) What is Synchrobench? - Correct Ans: A micro-benchmark suite in Java and C/C++ Goal: evaluate on a common ground (synchronisation techniques, data structure algorithms) Macro benchmarks cannot help at nailing down the causes of data structure bottlenecks Profiling tools are architecture specific
Questions and Solutions.
What is the current status of concurrency in Java? - Correct Ans: ~40 concurrent structures 3 architectures: SPARC, x86, Tilera 5 Synchronisation techniques
- CAS (non-blocking)
- Locks (eager, lazy acquirement)
- COW
- RCU (user-level)
- Transactional Memory (software libraries) What is the complexity (i.e. problems) of non-blocking trees? - Correct Ans: Some do not rebalance Some had data races Some are proprietary code Overall memory reclamation and lock-freedom is hard What is Thread Pinning? - Correct Ans: The binding of a process or thread to a specific core, can improve the performance of your code by increasing the percentage of local memory accesses COMP (compact pinning policy): ok for rapid peak perf. SCAT (scatter pinning policy): ok for scalability in TM Sequential vs Concurrent attributes? - Correct Ans: Sequential - methods take time, objects need meaningful state only between method calls, each method described in isolation, can add methods without affecting older methods Concurrent - method call is not an event, method call is an interval, everything can potentially interact with everything else
Questions and Solutions.
Define coherence vs consistency - Correct Ans: Coherence concerns only one memory location. The quality of being logical and consistent Consistency concerns apparent ordering for all locations. Done in the same way over time A memory system is coherent if for each location, we can serialise all operations to that location such that, operations performed by any processor appear in program order (i.e. the value returned by a read is the value written by the last write to that location) Define sequential consistency - Correct Ans: The result of each execution is the same if the operations by all processes on the same data store were executed in some sequential order and the operations of each individual process appear in this sequence in its program order What is explicit synchronisation? - Correct Ans: If sequential consistency is needed, then synchronise explicitly:
- Memory barrier instruction (flush unwritten caches, bring caches up to date), expensive tho What does the volatile keyword mean in Java? - Correct Ans: Ask compiler to keep a variable up-to-date with volatile keyword Define invariants - Correct Ans: a function, quantity, or property which remains unchanged when a specified transformation is applied What are characteristics of Database Transactions? - Correct Ans: Atomic (i.e. linearisable): to the outside world, the transaction happens indivisibly Consistent: the transaction does not violate system invariants Isolated: concurrent transactions do not interfere with each other Durable: once a transaction commits, the changes are permanent
Questions and Solutions.
What are properties of Memory Transactions? (STM and HTM) - Correct Ans: Similar to ACI, but: does not have durability Define Serialisability - Correct Ans: The guarantee that the execution of a set of transactions over multiple items is equivalent to some serial execution of the transactions It is non-serialisable if there is a cycle What does real-time precedence mean? - Correct Ans: If an operation o1 returns before another operations o2 is invoked then o1 precedes o2 with respect to real time Define Linearisability - Correct Ans: It provides a real-time guarantee on the behaviour of a set of single operations on a single object The result of each execution is equivalent to a sequential execution that respects the real- time precedence What are some ways to ensure linearisability? - Correct Ans: Critical sections - take sequential object, make each method a critical section Problems - blocking, no concurrency Define causal consistency - Correct Ans: Writes that are causally related (i.e. one happens before the other) must be seen by all processes in the same order. All processes agree on the order of causally-related operations All commercial memory models guarantee causal consistency What is strong and weak criteria of consistency? - Correct Ans: Strong (restrictive) - provides lots of safety guarantees, provides low performance
Questions and Solutions.
What is optimistic synchronisation? - Correct Ans: Find nodes without locking, then lock nodes, then check everything is ok (validation, done by two checks => yes still reachable from head, and yes x still points to y) What is lazy list-based synchronisation? - Correct Ans: Similar to optimistic, except contains never locks Logical delete => marks current node as removed Physical delete => redirects predecessors next Grabs two fine-grained locks per update operation. It grabs the locks just before detecting that an element in present
- Traverse
- Lock pred and curr
- Validate: check neither node is deleted, also check pred points to curr
- Try insert or delete
- Unlock An update returning unsuccessfully causing lots of stalls resulting in reduced concurrency What is version-list based synchronisation? - Correct Ans: This utilises pre-locking validation with a version try-lock <ver, lock> per node w/ ver = #acquirements Traversals don't acquire versioned try-locks
- Traverse
- Record version of pred
- Validate: by reading the version, an update only grabs the lock if v is absent and version is unchanged, again also check neither is deleted and pred points to curr
- Lock pred and curr node
Questions and Solutions.
- Insert or delete a node
- Unlock Compare lazy list and version list effective updates? - Correct Ans: Lazy list => all attempted updates grab locks, this is necessary to guarantee correctness Versioned list => only effective updates grab locks, this is concurrency optimal The lazy list is overly conservative while the versioned list is concurrency-optimal What is a read-write lock? - Correct Ans: Allows multiple readers in or a single writer in. This is often desirable as we want multiple readers of a datastructure What are pros/cons of locks? - Correct Ans: Refining lock granularity enhances concurrency. Minimising lock acquirement limits overhead What is the difference between spinning and waiting locks? - Correct Ans: Spinning => Immediately retry to take the lock Waiting => Stop executing until someone unlocks Why are waiting locks preferred in real-world applications? - Correct Ans: Waiting locks allow other applications to execute while you are waiting. Generic locks are well optimised and often are hybrid anyways. Often more expensive then spinlocks (uses complex schedular machinery and switching to kernel mode) Often paired with spinlocks => hybrid lock => try to spin for a short duration, if failed to acquire lock, then wait