This page was last modified 18:27, 2 October 2007.
Synchronization between processes
From Forum Nokia Wiki
One way to provide synchronization between processes is using semaphore. Here, we should use semaphore to communicate the state of the processes.
In Symbian C++, we achieve this using RSemaphore, RFastLock, RMutex, RCriticalSection, etc.
In Open C, the steps involved in using semaphore to synchronize are as follows:
- Create a semaphore using semget.
- When a process wants to synchronize with some other process, the first process can create the semaphore and set the semval with some condition.
- Once the other process has finished its task, satisfy the condition for which the other process is waiting for.
- Delete the created semaphore.
#include <sys/sem.h> #define SEM_KEY 1000 int main() { int semid = semget(SEM_KEY, 1, IPC_CREAT); int ret = semctl(semid, 0, SETVAL, 1); struct sembuf st = {0, 0, 0}; ret = semop(semid, &st, 1); // process -1 is blocked over here. ret = semctl(semid, 1, IPC_RMID); return 0; }
To communicate between the threads, we can use pthread_mutex for synchronization.
Note:There can be many ways of achieving this functionality;So, code snippets of other ways to do this are welcome.
Links
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| getting started ..? | dakoz | OMA DM/DS/CP | 11 | 2006-01-23 18:08 |
| Nokia 6620 crash in BT device/service loop | dcowing | Mobile Java Networking & Messaging & Security | 7 | 2005-02-08 21:40 |
| how to enable automatic synchronization | itsmemrm | OMA DM/DS/CP | 0 | 2007-10-17 11:35 |
| problem in N72 | ganngadhar | General Symbian C++ | 9 | 2007-04-18 16:22 |
| Virtual Memory | V R Krishna | General Symbian C++ | 6 | 2005-07-07 19:19 |
