semaphores and noatomic flag

Mihai Moise (mmoise@giref.ulaval.ca)
Mon, 04 Jun 2001 13:34:55 -0400


I write this to discuss the reasons why the semop system call should
have an IPC_NOATOMIC flag.

Suppose we have two processes, called client and server, which
communicate through a shared memory segment and two semaphores, and need
to synchonize their activities so that they don't operate simultaneously
except at startup.

The server would do,

down(smephore 0)

to wait for a message from the client. When the client needs the server
to execute, it would,

up(semaphore 0) /* wake up server */
down(semaphore 1) /* put itself to sleep */

after the server has completed its portion of the task, it would,

up(semaphore 1) /* wake up client */
down(semaphore 0) /* put iself to sleep */

The problem is that the two system calls make the whole process twice as
slow as it needs to be, and they are both needed because the semop
system call is implemented in an atomic manner. If the semop system call
had an IPC_NOATOMIC flag, then the each process would only have to do
one call,

semop(up semaphore 0 & down semaphore 1, IPC_NOATOMIC)

which would be interpreted in the kernel as the sequence of two system
calls I have written previously.

I want to know what other people think about this idea.

Mihai
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/