I once implemented something to solve the same problem in Java. So I have a high priority queue (hq) and a low priority queue (lq). Whenever an item is atted to the hq a token is also added to some associated high priority token queue (htq). Same for the lq and ltq.
Some thread or goroutine takes tokens from the htq as long as in contains tokens. You can add a count so that after any n tokens taken from the htq the ltq is checked whether it contains a token. Works fine until both, htp and ltp, are empty. You don't want to iterate over htp and ltp all the time till one contains a token again. So I introduced a semaphore on which the thread serving all these queues would be blocked till htq ot ltq recevie a new token. I thought that the sempahore would slow things down. So I did measurements with a bare bone concurrent queue and the priority queue. The difference in time to serve n tokens in htq and m tokens in ltq was very small also for high values of n and m. oyvin...@teigfam.net schrieb am Donnerstag, 29. April 2021 um 10:51:43 UTC+2: > I know from some years ago that go did not have any priority or ordered > select construct [1]. > > The idea is that select always is a nondeterministic choice operator, if > this is still so. Implemented with a random, I assume. > > Programming user defined "fair" algorithms or patterns is then not > possible, I believe. > > Is this still so in Go? No prioritised or ordered select in go? > > But is there still a way to code this by f.ex. combining several selects? > I saw a different take at this at [2], where the select is replaced a > single chan containing a chan bundle, thus becoming "deterministic". > > [1] Blog note Nondeterminism > <https://www.teigfam.net/oyvind/home/technology/049-nondeterminism/> > (disclaimer: > no ads, no gifts, only fun and expenses) > > [2] “A pattern for overcoming non-determinism of Golang select statement > <https://medium.com/@pedram.esmaeeli/a-pattern-for-overcoming-non-determinism-of-golang-select-statement-139dbe93db98> > (3May2019) > by Pedram Hajesmaeeli > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/bb6cbb5c-e240-4207-a5b1-5e7cfdd4dd64n%40googlegroups.com.