Does process priority influences race conditions in Linux

Assume I have two (or even more, smth like 10..100) processes that all write to same FIFO file. All these processes have a loop like this:

while (shouldRun) {
    // ... do some hard work ...
    flock(fd, LOCK_EX);
    write(fd, buffer, size);
    flock(fd, LOCK_UN);
}

So here is a racecondition. A couple of processes ask kernel to acquire exclusive lock. And a random one acquires the lock, every other process is waiting for someone to release its lock.

And now I want some individual process to acquire lock more frequently than other processes do, i.e. to have larger priority on lock acquiring.

Is it possible to do using nice or something like ionice etc.?


Source: linux

Leave a Reply