/* ----------------------------------------------------------------------------- Copyright 2021 Kevin P. Barry Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ----------------------------------------------------------------------------- */ // Author: Kevin P. Barry [ta0kira@gmail.com] // Waits for a thread barrier. @value interface BarrierWait { // Block until the barrier condition is satisfied. wait () -> (#self) } // A thread barrier validated using thread enumeration. concrete EnumeratedBarrier { refines ReadAt // Create a new barrier for a fixed number of threads. // // Args: // - Int: Non-negative number of threads. // // Returns: // - ReadAt: A list of the requested number of BarrierWait. These // should be passed out to the respective threads. // // Notes: // - Each thread must use its own BarrierWait; otherwise, there will be an // error-checking crash. For example, passing readAt(0) to all threads is // not allowed. // - If a BarrierWait no longer has any references (and thus cannot be used), // the barrier will be disabled. This will cause a crash if any thread is // waiting for (or subsequently waits for) the barrier. This does not mean // that you need to keep the ReadAt itself; one thread holding // a reference to each individual BarrierWait is sufficient. @type new (Int) -> (ReadAt) }