pthread_cleanup_push가 안되는거 같군요...
글쓴이: Hyun / 작성시간: 월, 2004/03/08 - 9:47오후
아래와 같이 했습니다.
#include <pthread.h>
#include <stdio.h>
pthread_t thread;
void callback( void *arg )
{
printf( "callback...\n" );
}
void *thread_fun( void *arg )
{
printf( "thread...\n" );
pthread_cleanup_push( callback, NULL );
while( 1 )
pthread_testcancel();
pthread_cleanup_pop( 1 );
return NULL;
}
int main( void )
{
pthread_create( &thread, NULL, thread_fun, NULL );
sleep( 2 );
pthread_cancel( thread );
printf( "alldid.\n" );
return 0;
}
위와같이 소스를 작성하고...
CROSS = powerpc-405-linux-gnu- CC = $(CROSS)gcc target = test objs = main.o all: $(target) $(target): $(objs) $(CC) $(CFLAGS) -lpthread -o $@ $^ .c.o: $(CC) $(CFLAGS) -c -o $@ $< clean: rm -f $(objs) $(target)
위와같이 Makefile를 만들었습니다.
그런데...
실행결과는...
[myid@local pthread_test]$ ./test thread... alldid. [myid@local pthread_test]$
라고 되네요...
콜백이 호출이 되지 않고있는데...
뭐가 잘못된건가요?
라이브러리 버그면 안되는데...
혹시 경험 있으신 분 계신가요?[/code]
Forums:


[code:1]int main( void ) {
int main( void ) { pthread_create( &thread, NULL, thread_fun, NULL ); sleep( 2 ); pthread_cancel( thread ); 추가 --> pthread_join(thread,NULL); 여기서 join을 하지 않으면 main함수에서 return한 후에 exit syscall이 수행되므로 다른 thread가 cleanup하기 전에 process가 종료되어 버릴 수도 있습니다. printf( "alldid.\n" ); return 0; }홋... 그렇군요...역시나 허접이였습니다. :mrgreen:
홋... 그렇군요...
역시나 허접이였습니다.
:mrgreen:
댓글 달기