Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Pthreads & Signals



Hello all,
	I'm trying to figure out howto resend a signal after I do 
something.  I have reduced my problem to the attached example.  If look 
though it the main thread gets a signal and then just tries to resend it 
back to the thr thread.  It just holds at the wait command...

Any ideas anyone?

Thanks,
Anthony 
-------------- next part --------------
#include <stdio.h>
#include <pthread.h>
#include <errno.h>

pthread_mutex_t 	guard_revc;
pthread_cond_t		got_data;

void *thr(void *);

int main( int argc, char *argv[] )
{

	pthread_t thread_recv;
	int result;
	
	pthread_cond_init( &got_data, NULL );
	pthread_mutex_init( &guard_revc, NULL );
		
	result = pthread_create(&thread_recv, NULL,
						thr, NULL );

	if ( result != 0 ) {
		perror( "pthread_create failed" );
		printf( "%s\n",strerror(errno));
		exit ( 3 );
	} 
	
	printf("main: wait cond\n");
	pthread_cond_wait( &got_data, &guard_revc );
	printf("main: got cond\n");
	pthread_cond_signal( &got_data );
	printf("main: send cond\n");
	
	pthread_join(thread_recv,NULL);
	
	return 0;
}

void *thr( void *arg ){

	pthread_mutex_lock( &guard_revc );
	printf("thr: Got Mutex\n");
	usleep(1);
	pthread_cond_signal( &got_data );
	printf("thr: Sent Signal\n");
	pthread_cond_wait( &got_data, &guard_revc );
	printf("thr: Got Signal\n");
	pthread_mutex_unlock( &guard_revc );
	printf("thr: Release Mutex\n");
	
	pthread_exit( NULL );
}



BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org