Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Oct 1998 10:43:10 -0400 (EDT)
From:      Daniel Eischen <eischen@vigrid.com>
To:        dbeck@freesoft.hu, freebsd-hackers@FreeBSD.ORG
Subject:   Re: pthreads and semctl problem
Message-ID:  <199810071443.KAA12225@pcnet1.pcnet.com>

next in thread | raw e-mail | index | archive | help

> This is the first time I post to this list. 
> Big hello to everyone :)
> 
> I started to port an application from DEC Unix to FreeBSD and
> an unexpected problem cropped out. The app runs on 3 threads
> and uses system V semaphores for synchronizing access to a
> shared memory block between unrelated processes. (It 
> communicates with unrelated processes using that shared
> memory block.) There are a couple of other reasons for why 
> I couldn't use pthread mutexes in this case. 
> 
> The problem is I found that when I block one thread with the
> semop call, all the other threads will be blocked. Why ? Is it
> a problem in the C library or the kernel ?
> 
> I compiled the program with the -pthread flag. Maybe I missed
> some other flags or switches ?
> 
> The same code works under DEC and Linux :(

FreeBSD pthreads currently doesn't wrap semop(), so any attempt to
wait for the semaphore will hang.  It doesn't look hard to fix
the threads library for semop; I might try implementing this when
I get some free time.

You can add a hack to your application to make it work by using
the IPC_NOWAIT flag on the semop call, and then if the thread
doesn't get the semaphore, issue a pthread_yield() which will let
other threads run.

Someone else reported this problem also.  Search the GNATS problem
database to see if it's there.  If not, submit a PR so it doesn't
get lost.

Dan Eischen
eischen@vigrid.com

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199810071443.KAA12225>