DragonFly BSD
DragonFly submit List (threaded) for 2005-03
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

libc_r/uthread/uthread_join.c


From: Marc Olzheim <marcolz@xxxxxxxx>
Date: Tue, 8 Mar 2005 01:11:59 +0100

I mailed this to FreeBSD a long time ago. I saw it wasn't fixed in DFly,
but I'm not sure whether libc_r is still used in DFly as I'm new to
it... Anyway, just for the fun of it:

Hi.

Is there a reason why in the case that a thread is not done yet,
pthread_join() does not call _thread_kern_sig_undefer() ?

We have a program where one thread consumes all CPU it can get for
blocks of data.
A status thread is spawned as soon as the main thread starts working on
a new block, printing an 'x % done' message and sleeping for a second in
a loop. When the block is processed, the status thread is
pthread_cancel()d and the main thread does a pthread_join() to wait for
the status thread to exit. Now, when the second block is to be
processed, a new status thread is spawned, but since signals are still
defered and the main thread needs all the cpu it can get, it doesn't get
scheduled in anymore.

The following fixed the problem in 4-STABLE and it seems to work ok, but
I'm no sure if there was a reason for the omission of the call in that
case...

Index: /usr/src/lib/libc_r/uthread/uthread_join.c
--- /usr/src/lib/libc_r/uthread/uthread_join.c	Tue Oct 22 16:44:03 2002
+++ /usr/src/lib/libc_r/uthread/uthread_join.c	Wed Dec 31 12:12:33 2003
@@ -137,6 +137,9 @@
 		ret = curthread->join_status.error;
 		if ((ret == 0) && (thread_return != NULL))
 			*thread_return = curthread->join_status.ret;
+
+		/* Undefer and handle pending signals, yielding if necessary: */
+		_thread_kern_sig_undefer();
 	} else {
 		/*
 		 * The thread exited (is dead) without being detached, and no



And another one, for terminating a backtrace (i386 only) while threaded:


Index: /usr/src/lib/libc_r/uthread/pthread_private.h
--- /usr/src/lib/libc_r/uthread/pthread_private.h	Tue Oct 22 16:44:02 2002
+++ /usr/src/lib/libc_r/uthread/pthread_private.h	Fri Apr 23 13:49:26 2004
@@ -80,7 +80,10 @@
 	fdata = (char *) (ucp)->uc_mcontext.mc_fpregs;	\
 	__asm__("frstor %0": :"m"(*fdata));		\
 } while (0)
-#define SET_RETURN_ADDR_JB(jb, ra)	(jb)[0]._jb[0] = (int)(ra)
+#define SET_RETURN_ADDR_JB(jb, ra)	do {		\
+	(jb)[0]._jb[0] = (int)(ra);			\
+	(jb)[0]._jb[3] = 0;				\
+} while (0)
 #elif	defined(__alpha__)
 #include <machine/reg.h>
 #define	GET_STACK_JB(jb)	((unsigned long)((jb)[0]._jb[R_SP + 4]))


Zlo

Attachment: pgp00002.pgp
Description: PGP signature



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