Changeset e4a2198 for doc


Ignore:
Timestamp:
Jun 1, 2023, 12:22:39 PM (12 months ago)
Author:
caparsons <caparson@…>
Branches:
ast-experimental, master
Children:
3eeeb88
Parents:
4897ffa
Message:

worked through Peter's changes to channel chapter

File:
1 edited

Legend:

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

    r4897ffa re4a2198  
    125125The deadlock detection in the \CFA channels is fairly basic but detects a very common channel mistake during termination.
    126126That is, it detects the case where threads are blocked on the channel during channel deallocation.
    127 This case is guaranteed to deadlock since there are no producer threads to supply values needed by the waiting consumer threads.
    128 Only if a user maintained a separate reference to the consumer threads and manually unblocks them outside the channel could the deadlock be avoid.
    129 However, without special consumer semantics, this unblocking would generate other runtime errors where the consumer attempts to access non-existing channel data or even a deallocated channel.
     127This case is guaranteed to deadlock since there are no other threads to supply or consume values needed by the waiting threads.
     128Only if a user maintained a separate reference to the blocked threads and manually unblocks them outside the channel could the deadlock be avoid.
     129However, without special semantics, this unblocking would generate other runtime errors where the unblocked thread attempts to access non-existing channel data or even a deallocated channel.
    130130More robust deadlock detection needs to be implemented separate from channels since it requires knowledge about the threading system and other channel/thread state.
    131131
    132132\subsection{Program Shutdown}
    133133Terminating concurrent programs is often one of the most difficult parts of writing concurrent code, particularly if graceful termination is needed.
    134 The difficulty for graceful termination often arises from the usage of synchronization primitives that need to be handled carefully during shutdown.
     134Graceful termination can be difficult to achieve with synchronization primitives that need to be handled carefully during shutdown.
    135135It is easy to deadlock during termination if threads are left behind on synchronization primitives.
    136136Additionally, most synchronization primitives are prone to \gls{toctou} issues where there is race between one thread checking the state of a concurrent object and another thread changing the state.
     
    179179For exceptions thrown from @remove@, the buffer element pointer is null.
    180180For exceptions thrown from @insert@, the element pointer points to the buffer element that the thread attempted to insert.
     181Utility routines @bool is_insert( channel_closed & e );@ and @bool is_remove( channel_closed & e );@ are provided for convenient checking of the element pointer.
    181182This element pointer allows the handler to know which operation failed and also allows the element to not be lost on a failed insert since it can be moved elsewhere in the handler.
    182183Furthermore, due to \CFA's powerful exception system, this data can be used to choose handlers based on which channel and operation failed.
     
    288289Flag variables are common in Go-channel shutdown-code to avoid panics on a channel, meaning the channel shutdown has to be communicated with threads before it occurs.
    289290Hence, the two flags @cons_done@ and @prod_done@ are used to communicate with the producers and consumers, respectively.
    290 Furthermore, producers and consumers need separate shutdown channels so producers terminate before the channel is closed to avoid panicking, and to avoid the case where all the consumers terminate first, which can result in a deadlock for producers if the channel is full.
     291Furthermore, producers and consumers need to shutdown separately to ensure that producers terminate before the channel is closed to avoid panicking, and to avoid the case where all the consumers terminate first, which can result in a deadlock for producers if the channel is full.
    291292The producer flag is set first;
    292293then after all producers terminate, the consumer flag is set and the channel is closed leaving elements in the buffer.
Note: See TracChangeset for help on using the changeset viewer.