Search code examples
linuxkernelschedulerspinlock

Linux Kernel - Can I lock and unlock Spinlock in different functions?


I'm new to Kernel programming and programming with locks.

Is it safe to lock and unlock a spinlock in different functions? I am doing this to synchronize the code flow.

Also, is it safe to use spinlock (lock & unlock) in __schedule()? Is it safe to keep the scheduler waiting to acquire a lock?

Thanks in advance.


Solution

  • Instead of spinlock, you can use a semaphore or a mutex. You should use spinlock in the same function for the littlest set of operations.