This website houses notes from my studies at the University of Liverpool. If you see any errors or issues, please do open an issue on this site's GitHub.
Semaphores are a token that you must acquire before entering a critical region. This could be a shared resource. Usage A semaphore is a variable that is used as a flag to indicate when a resource is free or in use: 0 means a resource is in use. 1 means...
Problem Suppose we have an object called Thing which has the following method: public void inc() { count++; } count is private to Thing, and is initially zero. Two threads, $T_1$ and $T_2$, both execute the following: thing.inc(); Indeterminacy Assume the inc() method does these three things within the processor:...
Dominance & Real Eigenvalues It is often the case in applications that we don’t need all the eigenvalues for a given matrix. We can check if a real matrix has a positive, real, largest eigenvalue using the Perron-Frobenius theorem. These conditions also ensure existence of positive real eigenvectors for the...
The process of the greedy algorithm is explained in this lecture: COMP111 - Informed Strategies The main idea is to bin pack using the largest items first. Greedy algorithm doesn’t always find an optimal solution but it is easy to implement. Knapsack Problem You want to steal the best items...
Mathematical Example Consider finding a single root using the quadratic formula: \[x=\frac{-b+\sqrt{b^2-4ac}}{2a}\] This can be split into several operations. Concurrent Operations These operations don’t rely on any other part of the expression. $t_1=-b$ $t_2=b\times b$ $t_3=4\times a$ $t_4=2\times a$ Serial Operations These parts have prerequisites. $t_5=t_3\times c$ $t_5=t_2-t_5$ $t_5=\sqrt{t_5}$ $t_5=t_1+t_5$...
A thread is an independent and parallel part of a process. Each thread has its own: Program counter Stack space However, unlike a process, threads share: Program code Data Open files and other system resources with the other member threads in the process. Threads are handled at a higher level...
Spectral methods refer to the study of matrices. Identity Matrix The identity matrix $I$ is a matrix which is all zero apart from the lead diagonal: \[\begin{pmatrix} 1 & 0 & 0\\ 0 & 1 & 0\\ 0 & 0 & 1\\ \end{pmatrix}\] For any matrix $A$: \[A\times I =...
Normal Program Flow In normal program flow, one subroutine will call another while the original is put on hold: graph LR main -->|1| x x -->|2| y y -->|3| x x -->|4| main This is called the call stack. Errors There are several ways to handle errors if they occur...
Using for loops on lists can be dangerous as their size is not static. We can separate the traversal logic from the underlying collection by using iterators. Iterator Design Pattern Iterators provide a way to access elements of an aggregate object sequentially without exposing its underling representation. Iterators are objects....