Is there any mechanism through which I can wake up a thread in another process without going through the kernel? The waiting thread might spin in a loop, no problem (each thread is pegged to a separate core), but in my case the sending thread has to be quick, and can’t afford to go through the kernel to wake up the waiting thread.
Share
No, if the other thread is sleeping (not on CPU). To wake up such thread you need to change its state into “RUNNING” by calling scheduler which is part of the kernel.
Yes, you can syncronize two threads or processes if both are running on different CPUs, and if there is shared memory between them. You should bind all threads to different CPUs. Then you may use spinlock:
pthread_spin_lockandpthread_spin_unlockfunctions from optional part of POSIX’s Pthread ('(ADVANCED REALTIME THREADS)';[THR SPI]); or any of custom spinlock. Custom spinlock most likely will use some atomic operations and/or memory barriers.Sending thread will change the value in memory, which is checked in loop by receiver thread.
E.g.
init:
then start threads.
waiting thread:
main thread: