Replies: 1 comment 2 replies
-
If you have a way of dispatching arbitrary code to worker threads, there is an old trick to do this. The worker keeps everything in thread-local storage and you do not use a separate channel for the state updates, but the same injector which also dispatches other work items. The work item then runs on the worker thread accessing the thread-local state and updating the state. Of course, this implies being able to dispatch something to specific or at at least all workers, c.f. e.g. |
Beta Was this translation helpful? Give feedback.
-
Hi! I'm working on a work-stealing thread pool using Crossbeam and have run into a challenge.
In my design, worker threads not only steal work but also need to receive messages from a channel to update their internal state periodically. To achieve this, I'm using:
channel
for state updates.Injector
for work-stealing task processing.The Challenge
How can worker threads avoid consuming CPU while waiting for work?
Ideally, I'd implement some kind of wake-up mechanism when jobs are submitted so that idle threads don’t spin-wait unnecessarily. However, designing a proper notification system seems quite complex.
Alternative Approach
I'm considering using Rayon's
ThreadPool
instead, but I have a few concerns:thread_local
, but that wouldn’t help if the state needs external updates.thread_local
, how would I update it in a predicable way between work being processed?Use Case
The goal of this thread pool is to perform atomic file reads using
pread
concurrently.Below is my current Crossbeam implementation:
Crossbeam Work-Stealing Threadpool
Any advice or suggestions would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions