Barrier - asimpy

Skip to content

# Barrier

Barrier that holds multiple processes until released.

## `Barrier`

Barrier to hold multiple processes.

Source code in `src/asimpy/barrier.py`

    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    class Barrier:
        """Barrier to hold multiple processes."""

        def __init__(self, env: "Environment"):
            """
            Construct barrier.

            Args:
                env: simulation environment.
            """
            self._env = env
            self._waiters = []

        async def wait(self):
            """Wait until barrier released."""
            evt = Event(self._env)
            self._waiters.append(evt)
            await evt

        def release(self):
            """Release processes waiting at barrier."""
            for evt in self._waiters:
                evt.succeed()
            self._waiters.clear()

### `__init__(env)`

Construct barrier.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`env` | `Environment` | simulation environment. | required

Source code in `src/asimpy/barrier.py`

    13
    14
    15
    16
    17
    18
    19
    20
    21
    def __init__(self, env: "Environment"):
        """
        Construct barrier.

        Args:
            env: simulation environment.
        """
        self._env = env
        self._waiters = []

### `release()`

Release processes waiting at barrier.

Source code in `src/asimpy/barrier.py`

    29
    30
    31
    32
    33
    def release(self):
        """Release processes waiting at barrier."""
        for evt in self._waiters:
            evt.succeed()
        self._waiters.clear()

### `wait()` `async`

Wait until barrier released.

Source code in `src/asimpy/barrier.py`

    23
    24
    25
    26
    27
    async def wait(self):
        """Wait until barrier released."""
        evt = Event(self._env)
        self._waiters.append(evt)
        await evt