Skip to content

Conversation

@JannePeltonen
Copy link
Collaborator

Explicitly state that a memory barrier can be reused without initializing it again.

Make it clear that no more than N threads may be inside odp_barrier_wait() for a barrier of N threads. Without this requirement, an application could e.g. wait a barrier in thread 1 and thread 2, and, when thread 2 returns from the barrier (at which point thread 1 is supposed to have been unblocked too), tell threads 3 and 4 to wait for the same barrier. If threads 3 and 4 manage to start waiting for the barrier before thread 1 has returned from odp_barrier_wait(), thread 1 may continue to be blocked in the counter based implementation used in multiple ODPs.

Clarify that a barrier must be initialized before first use and can be reinitialized if not in use. Make also a remark about the thread-unsafety of the initialization function.

@odpbuild odpbuild changed the title api: barrier: clarify thread barrier reuse [PATCH v1] api: barrier: clarify thread barrier reuse Sep 22, 2025
@MatiasElo MatiasElo added this to the v1.49.0 milestone Sep 23, 2025
Copy link
Collaborator

@psavol psavol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo corrections needed, otherwise ok.

@odpbuild odpbuild changed the title [PATCH v1] api: barrier: clarify thread barrier reuse [PATCH v2] api: barrier: clarify thread barrier reuse Dec 30, 2025
@JannePeltonen
Copy link
Collaborator Author

v2: fixed typos, added a test, rebased

Explicitly state that a memory barrier can be reused without initializing
it again.

Make it clear that no more than N threads may be inside odp_barrier_wait()
for a barrier of N threads. Without this requirement, an application could
e.g. wait a barrier in thread 1 and thread 2, and, when thread 2 returns
from the barrier (at which point thread 1 is supposed to have been
unblocked too), tell threads 3 and 4 to wait for the same barrier. If
threads 3 and 4 manage to start waiting for the barrier before thread 1
has returned from odp_barrier_wait(), thread 1 may continue to be blocked
in the counter based implementation used in multiple ODPs.

Clarify that a barrier must be initialized before first use and can be
reinitialized if not in use. Make also a remark about the thread-unsafety
of the initialization function.

Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
Reviewed-by: Jerin Jacob <jerinj@marvell.com>
Reviewed-by: Petri Savolainen <petri.savolainen@nokia.com>
Reviewed-by: Matias Elo <matias.elo@nokia.com>
Use atomic types for variables that may be accessed by multiple threads
simulteneously. Also remove a few unused lines of code and an outdated
comment.

Use of relaxed memory order in the custom barrier implementation is
dubious and probably wrong but not fixed by this commit.

Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
Reviewed-by: Matias Elo <matias.elo@nokia.com>
Add a test that reuses a thread barrier without reinitialization.

Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
Reviewed-by: Matias Elo <matias.elo@nokia.com>
@odpbuild odpbuild changed the title [PATCH v2] api: barrier: clarify thread barrier reuse [PATCH v3] api: barrier: clarify thread barrier reuse Dec 30, 2025
@JannePeltonen
Copy link
Collaborator Author

v3: added review tags, and now actually rebased

@MatiasElo MatiasElo added the API Ready API change ready to be merged (with the next API version increment) label Dec 30, 2025
@MatiasElo MatiasElo enabled auto-merge (rebase) December 30, 2025 08:14
@MatiasElo MatiasElo merged commit d5b9eb1 into OpenDataPlane:master Dec 30, 2025
164 checks passed
@JannePeltonen JannePeltonen deleted the api-thread-barrier branch December 30, 2025 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API Ready API change ready to be merged (with the next API version increment)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants