You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a library which produces many objects rapidly, where I want a pool of threads to pop one and work on it, which takes a while longer than how fast it's generated. Ideally I would like to have a small buffer of elements, so it's possible to append more ahead-of-time, in cases where tasks take a bit of time, but then speed up.
The mpsc queue we have is unbounded unfortunately. That is typically not what you want, since you don't want the set of queued items to grow unbounded (e.g. produce them faster than consume them).
However, by creating a Serializer, specifically a semaphore serializer, backed up with a stdTaksPool, you can get this behavior.
The serializer is essentially an atomic task counter that blocks when too many tasks are queued. By backing it up with an stdTaskPool the tasks themselves get executed in parallel.
Writing one isn't that difficult, and can be done outside this library to start with. Ping me on slack and I can help you get started.
More importantly though, you need to consider who owns what. Who owns the threadpool and who owns the specific tasks.
I have a library which produces many objects rapidly, where I want a pool of threads to pop one and work on it, which takes a while longer than how fast it's generated. Ideally I would like to have a small buffer of elements, so it's possible to append more ahead-of-time, in cases where tasks take a bit of time, but then speed up.
Right now for a queue there seems to be https://github.com/symmetryinvestments/concurrency/blob/334e522f9e23213788083a1363579f6398e0502d/source/concurrency/data/queue/mpsc.d and https://github.com/symmetryinvestments/concurrency/blob/334e522f9e23213788083a1363579f6398e0502d/source/concurrency/data/queue/waitable.d
(although they aren't really documented or mentioned in the README, so I'm not sure if they are usable)
Is there another primitive I could use or is this a new data type entirely?
The text was updated successfully, but these errors were encountered: