0

For my program, when a client joins a MQ that was created by a server, the server starts a thread and in that thread will create a private MQ that only one specific client will have the key to.

When I create a key, since it will be one of many, does it have to have a special name? Or can I use the same one when calling ftok()?

example code:

void *thread_function(void *arg){
        key_t keyT;
    int temp;
    temp = i;
    struct my_msgbuf bufT;
    keyT=ftok("server.c", 'B'); //create key for client[temp]
    if ((client[temp].mqID=msgget(keyT, 0666 | IPC_CREAT))==-1){ //private mq for client[temp]
        perror("msgget");
    }
}

Or will have I have to make a array of key_t's, a different key for each thread?

And does keyT=ftok("server.c", 'B'); create the same key anytime you use it?

alk
  • 69,737
  • 10
  • 105
  • 255
emanyalpsid
  • 329
  • 1
  • 5
  • 19
  • 1
    See http://stackoverflow.com/questions/7358400/whats-is-purpose-ftok-in-message-queues – amdn Apr 05 '13 at 18:32
  • If you want the threads to have different message queues, you will.need different keys. If you use a single key, you will have a single message queue. Subject to the named file not having changed between calls (same in ode, roughly), `ftok()` will generate the same key each time it is called with the same parameters. Indeed, that is one of its raisins d'être; it allows separate processes to come up with the same answer for the key. – Jonathan Leffler Apr 06 '13 at 10:41

0 Answers0