Allow quitting threads
commit75248d66b2823fcc7ee06c8f13008f1f62c1f25e
authorEdwin Brady <ecb10@st-andrews.ac.uk>
dateFri 7 Oct 2016, 17:47 (10 years ago)
parent8e43d11
libs/base/System/Concurrency/Channels.idr+4
@@ -61,3 +61,7 @@ export
6161unsafeRecv : (expected : Type) -> Channel -> IO (Maybe expected)
6262unsafeRecv a (MkConc pid ch_id) = getMsgFrom {a} pid ch_id
6363
64+||| Exit the thread immediately
65+export
66+stopThread : IO a
67+stopThread = Raw.stopThread
libs/base/System/Concurrency/Raw.idr+6
@@ -106,3 +106,9 @@ getMsgFrom {a} sender channel
106106 foreign FFI_C "idris_freeMsg" (Ptr -> IO ()) m
107107 pure (Just x)
108108
109+stopThread : IO a
110+stopThread = do vm <- getMyVM
111+ MkRaw res <- foreign FFI_C "idris_stopThread" (Ptr -> IO (Raw a)) vm
112+ pure res
113+
114+
rts/idris_rts.c+6
@@ -753,6 +753,12 @@ void* vmThread(VM* callvm, func f, VAL arg) {
753753 return vm;
754754}
755755
756+void* idris_stopThread(VM* vm) {
757+ close_vm(vm);
758+ pthread_exit(NULL);
759+ return NULL;
760+}
761+
756762// VM is assumed to be a different vm from the one x lives on
757763
758764VAL doCopyTo(VM* vm, VAL x) {
rts/idris_rts.h+1
@@ -309,6 +309,7 @@ void free_nullaries();
309309void init_signals();
310310
311311void* vmThread(VM* callvm, func f, VAL arg);
312+void* idris_stopThread(VM* vm);
312313
313314// Copy a structure to another vm's heap
314315VAL copyTo(VM* newVM, VAL x);