LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-27-2003, 05:59 AM   #1
socket9001
LQ Newbie
 
Registered: Dec 2003
Location: Israel
Distribution: Slackware
Posts: 21

Rep: Reputation: 15
pthreads


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 ?
 
Old 12-28-2003, 01:01 AM   #2
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
yes you have to free the message queue.
killing a thread: http://www.mcsr.olemiss.edu/cgi-bin/...pthread_kill+3
 
Old 12-29-2003, 12:23 AM   #3
Kumar
Member
 
Registered: Sep 2003
Location: Pune, India
Distribution: Red Hat
Posts: 106

Rep: Reputation: 15
To terminate a thread, you can use pthread_cancel(). And you will have to take care of the message queue or else the resource will remain in the system unless the machine is rebooted(can be seen using ipcs command and deleted using ipcrm command).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Pthreads a12ctic Linux - Software 1 06-09-2005 10:05 PM
Pthreads christheavatar Programming 4 03-05-2005 09:30 PM
pthreads ftgow Linux - Software 0 07-08-2004 03:55 AM
pthreads h/w Programming 5 10-09-2003 11:11 AM
pthreads fr0ggeh Linux - Software 9 07-18-2003 10:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration