-
Notifications
You must be signed in to change notification settings - Fork 187
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
Question: is it possible to implement non-blocking FIFO queue with luv? #546
Comments
I don't know the cqueues API so I'm not quite sure what it is that that FIFO implementation does to make it "non-blocking". How do you make a queue/stack non-blocking? Is it the access to it that you're controlling? Could you show an example usage? |
I will try to explain. Imagine that we have FIFO with some object inside. Let's say there is 5 objects. If we have 6 simultaneous requests, sixth request will face that FIFO is empty. Let's look at cqueues-fifo.lua. fifo:setempty(function(self)
cond:wait()
return fifo:pop()
end) And also function methods:push(...)
self.fifo:insert(...)
self.pollfd:signal(1)
end So, when we trying to Let's return to our example. With How to do the same with Hope I explained it understandable. |
@daurnimator do you understand what is being asked here? When I hear fifo, I think of the linux file objects created by @snoopcatt, do you just was a pure lua code library that creates a queue of arbitrary lua values or do you want something related to actual linux fifos? I don't understand what the empty thing that throws an error by default means. |
A first-in-first-out queue interface. https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics)#Computer_science i.e. you can The integration between a fifo and luv would be: "when I |
@daurnimator, Thanks I understand the general concept of fifo queues, but the title "with luv" made me think maybe it was related to linux syscalls. For starters, here is a simple FIFO queue with no max buffer size: local function fifo()
local reader = 0
local writer = 0
local function pop()
if reader < writer then
local value = queue[reader]
queue[reader] = nil
reader = reader + 1
return value
end
local current = coroutine.runing()
queue[reader] = current
reader = reader + 1
return coroutine.yield()
end
local function push(value)
if reader > writer then
local waiting = queue[writer]
queue[writer] = nil
writer = writer + 1
return coroutine.resume(waiting, value)
end
queue[writer] = value
writer = writer + 1
end
return {
pop = pop,
push = push,
}
end It will block the current coroutine on |
this of course wouldn't handle errors well; nor do you want random 'poppers' resumed from the context of the 'puller': you want the puller to be resume next time the main loop is hit. I guess in luv you'd use a
maybe; the example I wrote (back in 2015) that the OP linked doesn't have that feature though. |
True, I've often been in a context where that was the only option, but I like the idea of using async or something to keep them on clean stacks. |
Hello.
Looking for a solution (or even possibility) to implement non-blocking FIFO queue with libuv.
Just like that: https://gist.github.com/daurnimator/88e942022d4f3cabf57c but for luv instead of cqueues.
I'm ready to pay some bounty (like $100 in USDT or LTC) if someone suggests an answer.
The text was updated successfully, but these errors were encountered: