pthread offers a function to forcibly end a thread.
usefull if a thread is caught in blocking I/O which makes
it freeze.
the C code:
--- gwlib/gwthread-pthread.c 2005-04-13 18:13:38.000000000 +0200
+++ gwthread-pthread.c 2005-04-13 21:04:49.000000000 +0200
@@ -730,7 +730,7 @@ int gwthread_poll(struct pollfd *fds, lo
}
-void gwthread_sleep(double seconds)
+int gwthread_sleep(double seconds)
{
struct pollfd pollfd;
struct threadinfo *threadinfo;
@@ -755,6 +755,7 @@ void gwthread_sleep(double seconds)
if (ret == 1) {
flushpipe(pollfd.fd);
}
+ return ret;
}
@@ -801,4 +802,13 @@ static int pthread_sigmask()
{
return 0;
}
+
+int gwthread_cancel(long thread)
+{
+ struct threadinfo *th=THREAD(thread);
+
+ return pthread_cancel(th->self);
+}
+
+
#endif
The header:
--- gwlib/gwthread.h 2005-04-13 18:13:38.000000000 +0200
+++ gwthread.h 2005-04-13 21:04:10.000000000 +0200
@@ -139,8 +139,12 @@ int gwthread_pollfd(int fd, int events,
int gwthread_poll(struct pollfd *fds, long numfds, double timeout);
/* Sleep until "seconds" seconds have elapsed, or until another thread
- * calls gwthread_wakeup on us. Fractional seconds are allowed. */
-void gwthread_sleep(double seconds);
+ * calls gwthread_wakeup on us. Fractional seconds are allowed.
+ * as we need the return of poll, get it here.
+ * returns 0 on Timeout, positive value if the thread was
+ * awakened by another thread. -1 on error.
+ */
+int gwthread_sleep(double seconds);
/*
* Check wheather this thread should handle the given signal.
@@ -160,5 +164,10 @@ int gwthread_shouldhandlesignal(int sign
*/
int gwthread_dumpsigmask(void);
+/*
+ *make the thread forcibly go away
+ */
+int gwthread_cancel(long thread);
+
#endif
sorry, if the filemarks are incorrect.
Sincerely,
Wilfried Goesgens