Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Exemplos de filas de mensagens

From Wiki
Jump to: navigation, search
Article Metadata

Artigo
Tradução:
Por kyllercg
Última alteração feita por hamishwillee em 09 Dec 2011



Fila de mensagens

O código a seguir mostra como usar filas de mensagens.

#include <sys/msg.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
 
#define MSG_KEY 1000
pthread_t threadid;
 
void* MsgDSndThread(void* arg)
{
struct msgbuf *snd = (struct msgbuf*)malloc(16);
key_t fd;
snd->mtype = 1;
strcpy(snd->mtext, "message");
fd = msgget(MSG_KEY, IPC_CREAT);
msgsnd(fd, snd, 12, 0);
free(snd);
return 0;
}
 
void CreateThreadL()
{
pthread_create(&threadid,(pthread_attr_t *)NULL,MsgDSndThread, NULL);
}
 
int main()
{
struct msgbuf *rcv = (struct msgbuf*)malloc(16);
key_t fd = msgget(MSG_KEY, IPC_CREAT);
CreateThreadL();
msgrcv(fd, rcv, 6, 0, 0);
msgctl(fd, IPC_RMID, NULL);
free(rcv);
return 0;
}
This page was last modified on 9 December 2011, at 04:25.
238 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×