This page was last modified 21:09, 26 October 2007.
Exemplos de memória compartilhada
From Forum Nokia Wiki
Original: Shared Memory Example
O código a seguir mostra como usar memória compartilhada.
#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); // nome armazenado "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 relacionados
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| setting selected item in a CAknRadioButtonSettingPage | danielos1 | Symbian User Interface | 1 | 2003-10-01 00:52 |
| Nokia Comunicator 9500 | alvisone | General Discussion | 2 | 2004-03-01 07:01 |
| How to serialize an Image object | Pepper_91 | Mobile Java Networking & Messaging & Security | 4 | 2005-12-30 08:40 |
| png and jpg | simonesec | Mobile Java Media (Graphics & Sounds) | 3 | 2005-06-06 08:24 |
| How Can I delete readed SMS?? | jorom | PC Suite API and PC Connectivity SDK | 8 | 2006-02-01 11:14 |
