003 Linux System ProgrammingIssues, queries and suggestions related to Linux, Linux Programming, IPC, Interprocess Communication, Synchronization, Semaphore, System Programming, Linux Software Development.
You're trying to implement the thread semaphore between the server and the vendor using sem_init() so that only one thread can read the data from a client and send the data to the vendor for some operation and then, sending back to server using shared memory and you have implemented sem_wait() before sending the data to the vendor and after reading from the server you sem_post() it, right? If it's yes, then the possible reason for the semaphore variable not reflecting in sem_wait() after you sem_post() it in the vendor is the pshared argument in the sem_init(). The pshared variable should be 1 and the most important thing to make it happen is to create a shared memory containing the thread semaphore object so that both the processes can share that semaphore object.
Use thread semaphore, if your main thread is running more than once. And for pid and result, please go through you program one more time. I'm sure you can debug it.