Any package implementing FIFO mutex?

290 views
Skip to first unread message

ChrisLu

unread,
Sep 9, 2022, 3:12:46 PM9/9/22
to golang-nuts
"sync.Mutex" is not FIFO. Has any package implemented a dropping for FIFO mutex?

One similar solution is to use buffered channel, but it is limited by the buffer size, and requires non-trivial re-architecturing.

Chris

David Finkel

unread,
Sep 9, 2022, 3:41:04 PM9/9/22
to ChrisLu, golang-nuts
Not a drop-in replacement, but there is net/textproto.Pipeline. (intended for sequencing text-based network protocols going over a socket, but it's not too far off)

You'd call `Next()` to grab the sequence-handle and then call `p.StartRequest(id)` to grab the lock. Unlocking would be `p.EndRequest(id)`.
I think you can ignore the response-side for this use-case, but I'm not certain.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/f4772670-65d8-4b31-a71a-d01ad20214ebn%40googlegroups.com.

gbarr

unread,
Sep 10, 2022, 4:43:06 AM9/10/22
to golang-nuts
You could use golang.org/x/sync/semaphore NewWeighted(1) Aquire will return in order

Graham

Chris Lu

unread,
Sep 10, 2022, 4:52:55 AM9/10/22
to gbarr, golang-nuts
Thanks for sharing this gem!

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/VzwZ07n1oxY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/7290f721-cd9a-4c8c-914b-4f9742e0bcb7n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages