Skip to content

Commit

Permalink
Merge pull request #183 from illinois-cs241/st-arry-patch-2
Browse files Browse the repository at this point in the history
Error in unsigned bit shifting
  • Loading branch information
bhuvy2 authored Mar 17, 2022
2 parents eb6b723 + 559e0c7 commit c1cd1f0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions appendix/appendix.tex
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ \section{Implementing CVs with Mutexes Alone}
So how does this work?
Instead of allocating space which could lead to deadlock.
We keep the data structures or the linked list nodes on each thread's stack.
The linked list in the wait function is created \textbf{While the thread has the mutex lock} this is important because we may have a race condition on the insert and removal.
The linked list in the wait function is created \textbf{while the thread has the mutex lock.} This is important because we may have a race condition on the insert and removal.
A more robust implementation would have a mutex per condition variable.

What is the note about (dynamic)?
Expand All @@ -897,7 +897,7 @@ \section{Implementing CVs with Mutexes Alone}
After the last thread leaves, meaning when head is NULL, then the binding is lost.

The signal and broadcast functions merely tell either one thread or all threads respectively that they should be woken up.
\textbf{It doesn't modify the linked lists because there is no mutex to prevent corruption if two threads call signal or broadcast}
\textbf{It doesn't modify the linked lists because there is no mutex to prevent corruption if two threads call signal or broadcast.}

Now an advanced point.
Do you see how a broadcast could cause a spurious wakeup in this case? Consider this series of events.
Expand Down
2 changes: 1 addition & 1 deletion introc/language_facilities.tex
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ \subsection{Operators}
short sig = 1; // 0000000000000001
uns << 2; // 1111111000000100
sig << 2; // 0000000000000100
uns >> 2; // 1111111111100000
uns >> 2; // 0011111111100000
sig >> 2; // 0000000000000000
\end{lstlisting}
Note that shifting by the word size (e.g. by 64 in a 64-bit architecture) results in undefined behavior.
Expand Down

0 comments on commit c1cd1f0

Please sign in to comment.