Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trio.Barrier synchronization promitive #1434

Closed
ntninja opened this issue Mar 12, 2020 · 3 comments
Closed

trio.Barrier synchronization promitive #1434

ntninja opened this issue Mar 12, 2020 · 3 comments

Comments

@ntninja
Copy link

ntninja commented Mar 12, 2020

Trying to fix an edge case in my implementation of a TeeingReceiveStream, I discovered that I likely need a task synchronization primitive called a “barrier” (Python threading docs) to synchronize value read access between different tasks.

Would this be considered a good fit for inclusion into trio? It not being present right now, I'll have to write my own, so what I'm really asking is: Should I bother polishing it up and hand it in for review or not?

– A big trio fan 🙂

@njsmith
Copy link
Member

njsmith commented Mar 12, 2020

Would this be considered a good fit for inclusion into trio?

I dunno, maybe! I know it's something that shows up in various concurrency libraries, but I've never run into a case where I needed it myself, so I'm pretty fuzzy on what makes it useful. Which is annoying, because it makes it hard to know whether we've got the API right.

How will it help your TeeingReceiveStream?

@ntninja
Copy link
Author

ntninja commented Mar 13, 2020

After lots of debugging and testing, I wound up not needing the barrier after all. The synchronization provided by trio.open_memory_channel and the manually managed nursery (read: without async with) ended up being good enough – there were just two tricky edge cases with regards to nursery shutdown that I handled slightly wrong. (Not that something like that would surprise you. 😉)

You can view my barrier implementation here: https://pastebin.com/ay3uucfS
Knowing what I know now, I'd rewrite it from scratch using trio.hazmat.ParkingLot – the blueprint I used for this was written with preemptive multitasking in mind which makes everything much more complicated.

@Zac-HD
Copy link
Member

Zac-HD commented Mar 17, 2023

Closing this for now, as I don't think we should add new primitives without someone making a strong case for them 🙂

@Zac-HD Zac-HD closed this as completed Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants