Hello,
im working on a plugin, so basicly my program is a shared library...
i have an entry point function which the my plugin starts from which is something like that:
Code:
int plugin_main(...)
{
pthread_t tid;
pthread_create(&tid, NULL, &my_thread, NULL);
...
...
...
return 1;
}
as you can see, when i init my plugin i start a thread, here's it's code:
Code:
void *my_thread(void *x)
{
int qid;
key_t key = 33221;
msgbuf mb;
int flag = IPC_CREAT | 0666;
if((qid = msgget(key, flag)) == -1)
{
perror("msgget failed...");
return NULL;
}
while(1)
{
if(msgrcv(qid, &mb, SIZE, 1, 0) == -1)
{
perror("msgrcv failed!");
return NULL;
}
if(enabled)
doSomehing();
}
return NULL;
}
before my plugin is terminated, the function plugin_terminate will be called...
how do i end the thread from plugin_terminate()?
do i need to free the message queue before the plugin is terminated? does it takes care of itselff ?