[117] in Pthreads mailing list archive

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

Signal Handling in Proven threads

daemon@ATHENA.MIT.EDU (Andreas Jung)
Mon Sep 11 05:51:29 1995

From: ajung@hssun5.cs.uni-sb.de (Andreas Jung)
To: pthreads@MIT.EDU
Date: Mon, 11 Sep 1995 11:01:45 +0200 (MET DST)

Hi,

I wrote the following program that implements
the administrator-worker model. The program runs fine
under the Pthreads of Frank Mueller but it runs not
with the Proven PThreads. After some time I noticed that
the admin() function blocks at the sigwait() statement
although the main process sends signals via ptread_kill().
Is this a but in the Proven package ?

Thanks in advance 
- Andreas Jung

----------------------------------------------------------------------

#include <pthread.h>
#include <stdio.h>
#include <errno.h>
#include <signal.h>

#define TRUE 1
#define FALSE 0

char admin_command[255];

pthread_mutex_t mt_admin;

void * worker(char * arg)
{
	char str[255];

	sprintf(str,"finger @%s | sort >HOST.%s",arg,arg);
	system(str);
}

void * admin(void)
{
	int running = TRUE;
    sigset_t 			set,oset ;
    int 				signal; 
	pthread_attr_t	* 	ta_thread;
	pthread_t 		* 	t_thread;

    sigemptyset( &set ); 
    sigaddset( &set , SIGUSR1 );
    sigaddset( &set , SIGUSR2 );

    sigprocmask(SIG_BLOCK , &set , &oset); 

	while(running)
	{
		puts("worker working");
	
		signal = sigwait(&set);
   
		if (signal == SIGUSR2)
		{
			running = FALSE;
		}
 
		if (signal == SIGUSR1)
		{
			pthread_mutex_lock( &mt_admin );
	

			ta_thread = (pthread_attr_t * ) malloc(sizeof(pthread_attr_t));
			t_thread  = (pthread_t *) malloc(sizeof(pthread_t));

		    pthread_attr_init( ta_thread);
/*    		pthread_attr_setscope( ta_thread , PTHREAD_SCOPE_GLOBAL);
 */   		pthread_attr_setschedpolicy( ta_thread , SCHED_RR);
    		pthread_create(t_thread , ta_thread, worker, admin_command );
			pthread_mutex_unlock( &mt_admin );
		}
	}	
}
	
main(int argc, char **argv)
{
	char 			eingabe[255];
	int 			running=TRUE;

	pthread_attr_t 	ta_admin;
	pthread_t 		t_admin;

	pthread_init();

	pthread_mutex_init(&mt_admin , NULL);

	pthread_attr_init(&ta_admin);
	pthread_attr_setschedpolicy( &ta_admin , SCHED_RR);
	pthread_create(&t_admin , &ta_admin,  admin, NULL);

	while(running)
	{
		printf("Eingabe: "); fflush(stdout);
		scanf("%s",eingabe);

		if (strstr(eingabe,"quit") == NULL)
		{
			pthread_mutex_lock(&mt_admin);	
			strcpy(admin_command,eingabe);
			pthread_kill(t_admin, SIGUSR1);
			pthread_mutex_unlock(&mt_admin);
		}
		else 
		{
			pthread_kill(t_admin , SIGUSR2);
			running = FALSE;
		}
	}

		
	pthread_join( t_admin , NULL);
}

-- 

------------------------------------------------------------------------
      ///  Andreas Jung, Klosterstr. 21, D-66125 Saarbruecken, Germany 
     ///   Phone: +49-(0)681-302-3016 (work), +49-(0)6897-71959 (home) 
 \\\///    E-Mail: ajung@cs.uni-sb.de   IRC: YET   
  \XX/     WWW: http://hssun4.cs.uni-sb.de/~ajung
------------------------------------------------------------------------ 


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