No special means are required to transfer data between threads, because most of the data of threads are shared. Global variables, static global variables and data passed through pointers can be shared directly between threads. So the simplest way is to define a global queue so that every thread can access this queue. The main thread writes fd to the queue, and all threads in the thread pool take data from this queue. Of course, you can also pass the reference to the queue to each thread through parameters. Considering that the queue of this C++ standard library is not thread-safe, you may need to use a lock to ensure the thread-safety of the queue.
You can transfer it as you like, such as global variables, memory blocks on the heap, anything that is not tlsthread-local storage can be used for transmission, but the prerequisite is that it must be controlled by a lock. You can choose mutex, etc. for read and write control.
What the thread pool receives is an operation, not a value... Even if the thread in the thread pool has been created, it is blocked in the queue... You only need to deliver an operation with fd to the thread pool... If there is already an operation in the thread pool that is blocking and waiting for fd to come in, there will also be a condition variable to block the thread from running... When fd is ready, just notify the condition variable...
No special means are required to transfer data between threads, because most of the data of threads are shared. Global variables, static global variables and data passed through pointers can be shared directly between threads.
So the simplest way is to define a global queue so that every thread can access this queue. The main thread writes fd to the queue, and all threads in the thread pool take data from this queue. Of course, you can also pass the reference to the queue to each thread through parameters.
Considering that the queue of this C++ standard library is not thread-safe, you may need to use a lock to ensure the thread-safety of the queue.
You can transfer it as you like, such as global variables, memory blocks on the heap, anything that is not
tls
thread-local storage can be used for transmission, but the prerequisite is that it must be controlled by a lock.You can choose mutex, etc. for read and write control.
What the thread pool receives is an operation, not a value... Even if the thread in the thread pool has been created, it is blocked in the queue... You only need to deliver an operation with fd to the thread pool...
If there is already an operation in the thread pool that is blocking and waiting for fd to come in, there will also be a condition variable to block the thread from running... When fd is ready, just notify the condition variable...
PostThreadMessage can be considered under Windows.