summaryrefslogtreecommitdiff
path: root/lib/thread/test/future.myr
diff options
context:
space:
mode:
Diffstat (limited to 'lib/thread/test/future.myr')
-rw-r--r--lib/thread/test/future.myr53
1 files changed, 11 insertions, 42 deletions
diff --git a/lib/thread/test/future.myr b/lib/thread/test/future.myr
index e69e1af..760404b 100644
--- a/lib/thread/test/future.myr
+++ b/lib/thread/test/future.myr
@@ -2,49 +2,18 @@ use std
use sys
use thread
-use "util"
-
-var fut
-var nready : int32
-var ndone : int32
-
const main = {
- nready = 0
- ndone = 0
- fut = thread.mkfut()
- /* set after we have some waiters */
- mkherd(100, getfuture)
- while nready != 100
- /* spin */
- ;;
- std.put("done waiting for ready\n")
- std.assert(ndone == 0, "thread proceeded too soon\n")
- thread.futset(&fut, 666)
- std.assert(thread.futset(&fut, 1) == false, "double set future\n")
- while ndone != 100
- /* spin */
- ;;
- std.put("double set future ok")
- /* start up a few more to make sure we can still read */
- mkherd(50, getfuture)
- while ndone != 150
- /* spin */
- ;;
+ var f
-
- /* set ahead of time */
- ndone = 0
- fut = thread.mkfut()
- thread.futset(&fut, 666)
- std.assert(thread.futset(&fut, 666) == false, "double set future\n")
- mkherd(100, getfuture)
- while ndone != 100
- /* spin */
- ;;
-}
+ f = thread.mkfut()
+ thread.futput(f, 123)
+ std.assert(thread.futget(f) == 123, "the future is broken\n")
-const getfuture = {
- thread.xadd(&nready, 1)
- std.assert(thread.futget(&fut) == 666, "wrong value gotten from future")
- thread.xadd(&ndone, 1)
+ f = thread.mkfut()
+ thread.spawn({
+ std.usleep(10_000)
+ thread.futput(f, 321)
+ })
+ std.assert(thread.futget(f) == 321, "the future is broken\n")
}
+