[848] in Pthreads mailing list archive

home help back first fref pref prev next nref lref last post

Get help

daemon@ATHENA.MIT.EDU (teng_mt@188.net)
Tue Aug 10 22:53:06 1999

Date: 11 Aug 1999 02:31:58 -0000
Reply-To: teng_mt@188.net
From: teng_mt@188.net
To: pthreads@MIT.EDU

Dear Sr.

How can I send signal between threads in a process?
My developing platform is DEC Unix 4.0, I use pthread_kill(pthread_t id,int sig_id) to send signal to a thread, but a message "Hangup" will emerge when call the function above and all program will exit, why?

My program is:

#include <pthread.h>

pthread_t timer_id;
pthread_t scanner_id;
pthread_t runner_id;

pthread_attr_t attr;
sigset_t new;

void *timer_func(void *vp);
void *scanner_func(void *vp);
void *runner_func(void *vp);

main()
{
	sigemptyset(&new);
	sigaddset(&new,SIGUSR1);

	pthread_sigmask(SIG_BLOCK, &new,NULL);*/

	if(pthread_create(&timer_id,attr,timer_func,NULL) != 0)
		perror("Create timer");

	if(pthread_create(&scanner_id,attr,scanner_func,NULL) != 0)
		perror("Create scanner");

	if(pthread_create(&runner_id,attr,runner_func,NULL) != 0)
		perror("Create runner");

	while(1)
		sleep(10);
} /* end main */

void* timer_func(void *vp)
{
	printf("in timer_func\n");
	while(1)
	{
		if(pthread_kill(scanner_id,SIGUSR1) != 0)
			perror("timer");

		sleep(8);
	}
}

void *scanner_func(void *vp)
{
	int sig_id;

	printf("in scanner_func\n");
	while(1)
	{
		sigwait(&new,&sig_id);
		printf("scanner wait for %d\n",sig_id);
		pthread_kill(runner_id,SIGUSR1);
	}
}

void *runner_func(void *vp)
{
	int sig_id;

	printf("in runner_func\n");
	while(1)
	{
		sigwait(&new,&sig_id);
		printf("runner wait for %d\n",sig_id);
	}
}

My another question is about "pthread_attr_t attr" in program above.

pthread_attr_t attr variable must be declared in global and can not be initialized(call "pthread_attr_init()"), otherwise pthread_create will abort(error message "Invalid parameters"). 

Compiler will report errors if call pthread_create as
pthread_create(&thread_id, NULL, timer_func, NULL), compiler's error is
""0" is of type "long", and may not be converted to "struct CMA_T_HANDLE".  pthread_create(&t, NULL, sigint, NULL);".

Thanks lot!
My e-mail: teng_mt@188.net

Teng mintang, from Hangzhou P.R.China
1999/08/11

----------------------------------------------
;6S-J9SCCb7Q5gWSSJ<~O5M3 http://www.188.net
;6S-J9SCCb7Q5gWS:X?(O5M3 http://card.188.net


home help back first fref pref prev next nref lref last post