{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Applications of Semaphores

Applications of Semaphores - RPC Remote Procedure Call...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Applications of Semaphores: Remote Procedure Call RPC- Remote Procedure Call Assume we have two threads: A client and a server thread. A client thread fills up some arguments and wakes up a server thread. The client waits until the results from the server are ready. The server Wait until there is a cliet request wakes up, calls the function (Addition in this case) and it stores the results. T then it wakes up the client.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Remote Procedure Call Client Server ----------------- ------------------------ while (1) { // wait for incoming calls sema_wait(&_service_sem) mutex_lock(&_mutex); //Copy arguments _A = 3 _B = 2; //Wake up server sema_post(&_service_sem); sema_wait(&_done_sem); // Server wakes up. Do function C = _A + _B;
Background image of page 2
Remote Procedure Call You will use this approach in Lab 5 to communicate two or more processes using semaphores in shared memory but you will allow multiple threads in the server instead of only one. Client and Server will be in separate processes.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Remote Procedure Call class RPC { int _A; int _B; int _C; mutex_t _mutex; sema_t _service_sem; sema_t _done_sem;
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}