Boost logo

Boost-Commit :

From: hinnant_at_[hidden]
Date: 2007-12-12 21:15:15


Author: hinnant
Date: 2007-12-12 21:15:15 EST (Wed, 12 Dec 2007)
New Revision: 42002
URL: http://svn.boost.org/trac/boost/changeset/42002

Log:
Added.

Added:
   sandbox/committee/LWG/examples/native_handle.cpp (contents, props changed)

Added: sandbox/committee/LWG/examples/native_handle.cpp
==============================================================================
--- (empty file)
+++ sandbox/committee/LWG/examples/native_handle.cpp 2007-12-12 21:15:15 EST (Wed, 12 Dec 2007)
@@ -0,0 +1,52 @@
+#include <thread>
+
+template <class Thread>
+struct has_native_handle_type
+{
+ struct two {char x; char y;};
+ template <class U> static two test(...);
+ template <class U> static char test(typename U::native_handle_type*);
+public:
+ static const bool value = sizeof(test<Thread>(0)) == 1;
+};
+
+template <class Thread>
+void kill_thread(Thread t, std::false_type)
+{
+ static_assert(sizeof(Thread) == 0, "Having trouble porting kill_thread");
+}
+
+template <class Thread>
+void kill_thread(Thread t, std::true_type, std::false_type)
+{
+ // handle Windows?
+ windows_kill_thread(t.native_handle());
+}
+
+template <class Thread>
+void kill_thread(Thread t, std::true_type, std::true_type)
+{
+ pthread_kill(t.native_handle(), SIGKILL);
+}
+
+void kill_thread(std::thread t, std::true_type a)
+{
+ kill_thread(move(t), a, std::integral_constant<bool, std::is_same<std::thread::native_handle_type, pthread_t>::value>());
+}
+
+void kill_thread(std::thread t)
+{
+ kill_thread(move(t), std::integral_constant<bool, has_native_handle_type<std::thread>::value>());
+}
+
+void f()
+{
+ while (true)
+ ;
+}
+
+int main()
+{
+ std::thread t(f);
+ kill_thread(move(t));
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk