From owner-freebsd-current Fri Oct 2 00:59:45 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id AAA16160 for freebsd-current-outgoing; Fri, 2 Oct 1998 00:59:45 -0700 (PDT) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from badlans.lanminds.com (badlans.lanminds.com [208.1.127.253]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id AAA16155 for ; Fri, 2 Oct 1998 00:59:44 -0700 (PDT) (envelope-from rrs@badlans.lanminds.com) Received: (from rrs@localhost) by badlans.lanminds.com (8.8.6/8.8.6) id BAA14115 for current@freebsd.org; Fri, 2 Oct 1998 01:00:47 -0700 (PDT) Date: Fri, 2 Oct 1998 01:00:47 -0700 (PDT) From: Robert Schulhof Message-Id: <199810020800.BAA14115@badlans.lanminds.com> To: current@FreeBSD.ORG Subject: thread behavior Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Hi, I am not sure if this is the expected behavior according to the current IEEE standard, but sleep calls in any thread seem to suspend all threads. Also when a thread waits on a semop it seems to put the whole process to sleep. Are semaphores thread safe? I've tried compiling with cc and with egcs 1.1. The weird part is that the program will occasionally work correctly ( The semop calls, that is. sleep doesn't work). This program behaves as I expect Solaris 2.5.1. Under FreeBSD 2.2.7-Stable it freezes my terminal :-) Might be pilot error. Also, ACE wrappers, which worked before the recent changes to libc_r, now produces the following in the Semaphore/Threads test: Fatal error 'Dead thread has resumed' at line ? in file /usr/src/src/lib/libc_r/ uthread/uthread_exit.c (errno = ?) I get this error about 30% of the time. I'm just learning how to use ACE wrappers so I shouldn't attempt to figure that one out. This was after cvsup around 9:30 PM PDT 30 Sep. Thanks! I know you're busy so ignore unless this helps with the 3.0 Beta shakeout. I include the test below. define TEST_SLEEP to test sleep in a thread. #include #include #include #include #include #define NUM_THR 12 #define SEMKEY 0x420ffL #define PERMS 0666 void hanging_by_a(int *i); static struct sembuf op_lock[2]={ 0,0,0,0,1,0}; static struct sembuf op_unlock[1]={0,-1,IPC_NOWAIT}; main() { int i,semid; pthread_t tid[NUM_THR]; if ( (semid=semget(SEMKEY,1,IPC_CREAT | PERMS)) < 0 ){ perror("Semget"); exit(1); } fprintf(stderr,"Semaphore ID: %d\n",semid); /* anchors away ! */ semop(semid, &op_unlock[0], 1); if ( semop(semid, &op_lock[0], 2) < 0 ){ perror("lock sem"); exit(1); } for (i=0; i < NUM_THR; i++){ if ( pthread_create(&tid[i], NULL, (void *)hanging_by_a, (void *) &semid) ) perror("pthread_create"); fprintf(stderr,"Spawned thread #%d %u\n",i,tid[i]); } if ( semop(semid, &op_unlock[0], 1) < 0 ){ perror("lock sem"); exit(1); } for (i=0; i < NUM_THR; i++){ pthread_join(tid[i], NULL); fprintf(stderr,"Reaped thread %d %u\n",i,tid[i]); } } void hanging_by_a(int *sid) { pthread_t me; me = pthread_self(); fprintf(stderr,"I am tid %u Semaphore ID %u\n", me,*sid); if ( semop(*sid, &op_lock[0], 2) < 0 ){ perror("Thread lock sem"); } fprintf(stderr,"Thread %u has the lock\n", me); #ifdef TEST_SLEEP sleep(1); #endif if ( semop(*sid, &op_unlock[0], 1) < 0 ){ perror("Thread lock sem"); } fprintf(stderr,"Thread %u freed lock\n", me); pthread_exit(NULL); } Robert Schulhof UNIX System Administrator LanMinds Internet. (LMI Net) rrs@lmi.net http://www.lmi.net (510) 843-6389 VOX (510) 843-6390 FAX To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message