Search code examples
c++clinuxsemaphorecontext-switching

Minimize Context Switching Time between process


I have 4 process sharing a common semaphore, all the process have the same priority. The critical region inside the lock, has the read/write operation including the fflush() call.

In the logs, I observed that after giving off the semaphore from a particular process, there is a considerable amount of time taken by other process to acquire the lock.

Since, all the 4 process gets locked at the same point, there is a performance issue on an embedded device. If the lock is shared between threads, pthread_cond_t can be used to minimize the switching time. Now, what can be done to minimize the switching time between processes?


Solution

  • Context switch between processes held inside kernel. It's a job of kernel scheduler to do the context switching, so you can't do much here other than trying to speed up scheduler context switching path. Another alternative might be to try figure out the problem and to improve your app by reducing lock contention (perhaps).