Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 21:09, 26 October 2007.

Exemplos de filas de mensagens

From Forum Nokia Wiki

Original: Message Queues Example


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;
}
Related Discussions
Thread Thread Starter Forum Replies Last Post
Forum Nokia WRT Webinar Q&A (In Portuguese) bill.volpe WRT Widget Development 0 2008-06-13 16:35
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX