Changeset 7ed01be


Ignore:
Timestamp:
Jul 17, 2023, 12:03:56 PM (11 months ago)
Author:
caparsons <caparson@…>
Branches:
master
Children:
494a7e5
Parents:
dbf5e18
Message:

smoothed over 7.5 intro

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/colby_parsons_MMAth/text/waituntil.tex

    rdbf5e18 r7ed01be  
    1515
    1616Now the problem is extended.
    17 Some stalls are wheelchair accessible and some stalls have specific sexual orientation.
     17Some stalls are wheelchair accessible and some stalls have specific gender identification.
    1818Each person (thread) may be limited to only one kind of stall or may choose among different kinds of stalls that match their criteria.
    1919Immediately, the problem becomes more difficult.
     
    4444Guards are a conditional operator similar to an @if@, except they apply to the resource being waited on.
    4545If a guard is false, then the resource it guards is not in the set of resources being waited on.
    46 If all guards are false, the ALT does nothing and the thread continues.
     46If all guards are false, the ALT, Occam's \gls{synch_multiplex} statement, does nothing and the thread continues.
    4747Guards can be simulated using @if@ statements as shown in~\cite[rule~2.4, p~183]{Roscoe88}
    4848\begin{lstlisting}[basicstyle=\rm,mathescape]
     
    377377
    378378\section{\lstinline{waituntil} Implementation}
    379 The @waituntil@ statement is not inherently complex, and the pseudo code in presented in Figure~\ref{f:WU_Impl}.
     379The @waituntil@ statement is not inherently complex, and the pseudo code is presented in Figure~\ref{f:WU_Impl}.
    380380The complexity comes from the consideration of race conditions and synchronization needed when supporting various primitives.
    381381The basic steps of the @waituntil@ statement are:
     
    388388while ( statement predicate not satisfied ) {   $\C{// check predicate}$
    389389        // block
    390         for ( resource in waituntil statement )         $\C{// run true code blocks}$
     390        for ( resource in waituntil statement ) {       $\C{// run true code blocks}$
     391        if ( statement predicate is satisfied ) break;
    391392                if ( resource is avail ) run code block
    392 }
    393 for ( resource in waituntil statement ) {
    394         if ( statement predicate is run-satisfied ) break;
    395         if ( resource is avail ) run code block
     393    }
    396394}
    397395for ( node in s )                                                               $\C{// deregister nodes}\CRT$
    398         if (unregister_select( resource, node ) ) run code block
    399 \end{cfa}
    400 Each clause has a couple of statuses, UNSAT when not available, SAT when available and not run and RUN when it is available and the associated code block was run.
    401 The first while ( statement predicate not satisfied) waits until the predicate is satisfied, where UNSAT = false and SAT = true and RUN = true.
    402 The if ( statement predicate is run-satisfied ) considers a status of RUN = true and all other statuses to be false.
    403 
     396        if ( unregister_select( resource, node ) ) run code block
     397\end{cfa}
    404398\caption{\lstinline{waituntil} Implementation}
    405399\label{f:WU_Impl}
     
    416410The thread executing the @waituntil@ then loops until the statement's predicate is satisfied.
    417411In each iteration, if the predicate is unsatisfied, the thread blocks.
    418 If clauses becomes satisfied, the thread unblocks, and for each satisfied the block fails and the thread proceeds, otherwise the block succeeds.
     412If clauses becomes satisfied, the thread unblocks, and for each satisfied clause the block fails and the thread proceeds, otherwise the block succeeds (like a semaphore where a block is a @P()@ and a satisfied clause is a @V()@).
    419413After proceeding past the block all clauses are checked for completion and the completed clauses have their code blocks run.
     414While checking clause completion, if enough clauses have been run such that the statement predicate is satisfied, the loop exits early.
    420415In the case where the block succeeds, the thread will be woken by the thread that marks one of the resources as available.
    421416
     
    423418Once the thread escapes the loop, the @select_nodes@ are unregistered from the resources.
    424419\end{enumerate}
    425 Pseudocode detailing these steps is presented in the following code block.
    426420
    427421These steps give a basic overview of how the statement works.
     
    445439In detail, when a thread waits on multiple locks via a @waituntil@, it enqueues a @select_node@ in each of the lock's waiting queues.
    446440When a @select_node@ reaches the front of the lock's queue and gains ownership, the thread blocked on the @waituntil@ is unblocked.
    447 Now, the lock is temporarily held by the @waituntil@ thread until the node is unregistered, versus the thread waiting on the lock
     441Now, the lock is temporarily held by the @waituntil@ thread until the node is unregistered, versus the thread waiting on the lock.
    448442To prevent the waiting thread from holding many locks at once and potentially introducing a deadlock, the node is unregistered right after the corresponding code block is executed.
    449443This prevents deadlocks since the waiting thread will never hold a lock while waiting on another resource.
     
    510504Not all types in a @waituntil@ have an internal lock, and when using non-channel types acquiring all the locks incurs extra unneeded overhead.
    511505Instead this race is consolidated in \CFA in two phases by having an intermediate pending status value for the race.
    512 This race case is detectable, and if detected the thread attempting to signal will first race to set the race flag to be pending.
     506This race case is detectable, and if detected, producer will first race to set its own race flag to be pending.
    513507If it succeeds, it then attempts to set the consumer's race flag to its success value.
    514508If the producer successfully sets the consumer race flag, then the operation can proceed, if not the signalling thread will set its own race flag back to the initial value.
     
    518512Channels in \CFA have exception based shutdown mechanisms that the @waituntil@ statement needs to support.
    519513These exception mechanisms were what brought in the @on_selected@ routine.
    520 This routine is needed by channels to detect if they are closed upon waking from a @waituntil@ statement, to ensure that the appropriate behaviour is taken.
     514This routine is needed by channels to detect if they are closed upon waking from a @waituntil@ statement, to ensure that the appropriate behaviour is taken and an exception is thrown.
    521515
    522516\subsection{Guards and Statement Predicate}\label{s:wu_guards}
Note: See TracChangeset for help on using the changeset viewer.