This page was last modified 05:51, 1 October 2007.
Shared Memory Example
From Forum Nokia Wiki
Example Code is as follows(code follows the steps described in the above link):
#include <sys/shm.h> #include <string.h> #include <pthread.h> pthread_t threadid; #define SHM_KEY 1000 void* ShmReadThread(void* arg) { int shmid = shmget(SHM_KEY, 1024, IPC_CREAT); char* ch = (char*)shmat(shmid, 0, 0); char name[10]; strncpy(name, ch, 3); // name contained "abc" shmdt(ch); return 0; } void CreateThreadL() { pthread_create(&threadid,(pthread_attr_t *)NULL,ShmReadThread, NULL); } int main() { char* ch; int shmid = shmget(SHM_KEY, 1024, IPC_CREAT); int threadRetVal = 0; if( shmid == -1) return -1; ch = (char*)shmat(shmid, 0, 0); if((int)ch == -1) { shmctl(shmid, IPC_RMID, NULL); return -1; } strcpy(ch, "abc"); CreateThreadL(); pthread_join(threadid, (void**)threadRetVal); shmdt(ch); shmctl(shmid, IPC_RMID, NULL); return 0; }
Links
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Flashy Red Lights!!! | nmhurst | Nokia M2M | 1 | 2003-09-03 09:05 |
| How to dynamically detect install device and change target path in pkg file | JSHEBNF | General Symbian C++ | 5 | 2008-05-13 10:21 |
| Codes is not working in a new thread | Skygyl | General Symbian C++ | 3 | 2008-01-29 05:12 |
| Identifying VM | cassioli | Mobile Java General | 10 | 2007-11-13 11:07 |
| How much the size of persistant memory storage of N7210/6610 (series 40) ? | kapot | Mobile Java General | 3 | 2003-05-07 09:49 |
