libkse / libthr bugs?

Mike Makonnen mtm at identd.net
Fri Jun 27 15:42:31 PDT 2003


On Fri, 27 Jun 2003 07:14:43 -0400 (EDT)
Daniel Eischen <eischen at vigrid.com> wrote:

> 
> To answer your first question, yes, I think it's necessary.
> Here's an example:
> 
> 	void
> 	sigalarmhandler(int sig)
> 	{
> 		longjmp(env, 1);
> 	}
> 
> 	int
> 	somenslookup(...)
> 	{
> 		...
> 		alarm(5);	/* Wait a maximum of 5 seconds. */
> 		if (setjmp(env) == 0) {
> 			nsdispatch(...);
> 			return (0);
> 		}
> 		return (-1);
> 	}
> 
> Now perhaps this isn't the best example; imagine using
> something that used malloc()/free() or any one of the other
> locked libc functions.  There is also the use of application
> level-locks which should work similarly, but by using libc
> example I avoid any argument about "the application shouldn't
> be doing that" :-)

If I understand correctly what you are saying is if the alarm fires before
somenslookup() returns successfully, the longjmp will make it return
unsuccessfully, and if it happened to be put on a queue in nsdispatch() it will
return to its caller still on the queue (which we clearly don't want). 

How is this any different than holding some other resource? For example, if
it had managed to aquire the lock before the longjmp from the signal handler?
See below for what I mean.

> It's also possible that the thread calls the same set
> of libc functions again, and if it isn't removed from
> the internal mutex queue, then you'd get the exact
> error message Marcel was seeing (already on mutexq).

I'm glad you brought this last point up because that has been on my mind as
well. Let's say an application is in one of the locked libc functions, receives
a signal and calls that same libc function from it's signal handler.
Furthermore, let's say that the thread had just aquired a lock in the libc
funtion before handling the signal. When this thread called the same libc
function from the signal handler and tried to aquire the same lock again, would
it not deadlock against itself?

So, the problem is not that the mutex/cond queues are special. It's that locking
from within libc in general is special, right?

I guess part of what has me confused is why the queues are being treated so
specially. I think the problem is one of general re-entrancy for library
functions designated async or thread safe.  If so, then once I have a proper
handle on the issues I can start addressing them in libthr.


Cheers.
-- 
Mike Makonnen  | GPG-KEY: http://www.identd.net/~mtm/mtm.asc
mtm at identd.net | D228 1A6F C64E 120A A1C9  A3AA DAE1 E2AF DBCC 68B9
mtm at FreeBSD.Org| FreeBSD - The Power To Serve


More information about the freebsd-threads mailing list