diff -u --recursive --new-file asterisk-0.5.0/apps/app_qcall.c.unload2 asterisk-0.5.0/apps/app_qcall.c
--- asterisk-0.5.0/apps/app_qcall.c.unload2	Sat Nov  1 03:40:29 2003
+++ asterisk-0.5.0/apps/app_qcall.c	Sat Nov  1 03:47:25 2003
@@ -71,6 +71,7 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/file.h>
+#include <sys/signal.h>
 #include "../astconf.h"
 
 static char qdir[255];
@@ -113,6 +114,8 @@
 	if (debug) printf("@@@@ qcall starting at %s",ctime(&t));
 	for(;;)
 	   {
+	   	pthread_testcancel();
+
 		time(&t);
 		dirp = opendir(qdir);
 		if (!dirp)
@@ -357,6 +360,11 @@
 int unload_module(void)
 {
 	STANDARD_HANGUP_LOCALUSERS;
+	if (qcall_thread) {
+		pthread_cancel(qcall_thread);
+		pthread_kill(qcall_thread, SIGURG);
+		pthread_join(qcall_thread, NULL);
+	}
 	return 0;
 }
 
diff -u --recursive --new-file asterisk-0.5.0/channels/chan_iax2.c.unload2 asterisk-0.5.0/channels/chan_iax2.c
--- asterisk-0.5.0/channels/chan_iax2.c.unload2	Sun Nov  2 21:45:57 2003
+++ asterisk-0.5.0/channels/chan_iax2.c	Sun Nov  2 21:52:29 2003
@@ -4757,6 +4757,7 @@
 				iax_frame_free(freeme);
 		}
 		ast_mutex_unlock(&iaxq.lock);
+		pthread_testcancel();
 		res = ast_sched_wait(sched);
 		if ((res > 1000) || (res < 0))
 			res = 1000;
@@ -5741,6 +5742,7 @@
 	int x;
 	/* Cancel the network thread, close the net socket */
 	pthread_cancel(netthreadid);
+	pthread_kill(netthreadid, SIGURG);
 	pthread_join(netthreadid, NULL);
 	close(netsocket);
 	for (x=0;x<IAX_MAX_CALLS;x++)
diff -u --recursive --new-file asterisk-0.5.0/channels/chan_iax.c.unload2 asterisk-0.5.0/channels/chan_iax.c
--- asterisk-0.5.0/channels/chan_iax.c.unload2	Sun Nov  2 21:47:18 2003
+++ asterisk-0.5.0/channels/chan_iax.c	Sun Nov  2 21:53:03 2003
@@ -4282,6 +4282,7 @@
 				ast_iax_frame_free(freeme);
 		}
 		ast_mutex_unlock(&iaxq.lock);
+		pthread_testcancel();
 		res = ast_sched_wait(sched);
 		if ((res > 1000) || (res < 0))
 			res = 1000;
@@ -5172,6 +5173,7 @@
 	int x;
 	/* Cancel the network thread, close the net socket */
 	pthread_cancel(netthreadid);
+	pthread_kill(netthreadid, SIGURG);
 	pthread_join(netthreadid, NULL);
 	close(netsocket);
 	for (x=0;x<AST_IAX_MAX_CALLS;x++)
diff -u --recursive --new-file asterisk-0.5.0/channels/chan_phone.c.unload2 asterisk-0.5.0/channels/chan_phone.c
--- asterisk-0.5.0/channels/chan_phone.c.unload2	Sun Nov  2 21:51:43 2003
+++ asterisk-0.5.0/channels/chan_phone.c	Sun Nov  2 21:51:43 2003
@@ -30,6 +30,7 @@
 #include <arpa/inet.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
+#include <sys/signal.h>
 #include <linux/telephony.h>
 /* Still use some IXJ specific stuff */
 #include <linux/ixjuser.h>
@@ -836,6 +837,8 @@
 		/* Okay, now that we know what to do, release the interface lock */
 		ast_mutex_unlock(&iflock);
 		
+		pthread_testcancel();
+		
 		/* And from now on, we're okay to be killed, so release the monitor lock as well */
 		ast_mutex_unlock(&monlock);
 		/* Wait indefinitely for something to happen */
@@ -911,9 +914,8 @@
 	}
 	if (monitor_thread != -1) {
 		pthread_cancel(monitor_thread);
-#if 0
+		pthread_kill(monitor_thread, SIGURG);
 		pthread_join(monitor_thread, NULL);
-#endif
 	}
 	/* Start a new monitor */
 	if (pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
@@ -1157,6 +1159,7 @@
 	if (!ast_mutex_lock(&monlock)) {
 		if (monitor_thread > -1) {
 			pthread_cancel(monitor_thread);
+			pthread_kill(monitor_thread, SIGURG);
 			pthread_join(monitor_thread, NULL);
 		}
 		monitor_thread = -2;
diff -u --recursive --new-file asterisk-0.5.0/channels/chan_sip.c.unload2 asterisk-0.5.0/channels/chan_sip.c
--- asterisk-0.5.0/channels/chan_sip.c.unload2	Sun Nov  2 22:21:18 2003
+++ asterisk-0.5.0/channels/chan_sip.c	Sun Nov  2 22:22:34 2003
@@ -5231,6 +5231,7 @@
 		ast_mutex_unlock(&iflock);
 		/* Don't let anybody kill us right away.  Nobody should lock the interface list
 		   and wait for the monitor list, but the other way around is okay. */
+#if 0
 		ast_mutex_lock(&monlock);
 		/* Lock the network interface */
 		ast_mutex_lock(&netlock);
@@ -5239,6 +5240,7 @@
 		/* And from now on, we're okay to be killed, so release the monitor lock as well */
 		ast_mutex_unlock(&monlock);
 		pthread_testcancel();
+#endif
 		/* Wait for sched or io */
 		res = ast_sched_wait(sched);
 		if ((res < 0) || (res > 1000))
@@ -5247,6 +5249,7 @@
 		if (fastrestart)
 			res = 1;
 		res = ast_io_wait(io, res);
+		pthread_testcancel();
 		ast_mutex_lock(&monlock);
 		if (res >= 0) 
 			ast_sched_runq(sched);
