diff --git a/src/kernel/core.lisp b/src/kernel/core.lisp index 5836033..1bc1304 100644 --- a/src/kernel/core.lisp +++ b/src/kernel/core.lisp @@ -502,6 +502,17 @@ Calling `broadcast-task' from inside a worker is an error." (repeat worker-count (push-queue t to-workers)) (map-into (make-array worker-count) (lambda () (receive-result channel))))) +(defun submit-bare-task (fn &rest args) + "Schedule a task to be run with the current value of `*kernel*'. + +The result of the function call is discarded." + (declare #.*normal-optimize*) + (submit-raw-task (make-task (task-lambda (apply fn args))) + *kernel*)) + +(defmacro bare-task (&body body) + `(submit-bare-task (lambda () ,@body))) + (defun track-exit () (setf *lisp-exiting-p* t)) diff --git a/src/kernel/package.lisp b/src/kernel/package.lisp index 8f23fa8..c96d123 100644 --- a/src/kernel/package.lisp +++ b/src/kernel/package.lisp @@ -51,6 +51,8 @@ (:export #:make-channel #:submit-task #:broadcast-task + #:submit-bare-task + #:bare-task #:submit-timeout #:cancel-timeout #:receive-result diff --git a/test/kernel-test.lisp b/test/kernel-test.lisp index 5fd71a9..f78a404 100644 --- a/test/kernel-test.lisp +++ b/test/kernel-test.lisp @@ -697,7 +697,15 @@ (signals error (receive-result channel))) (signals error - (broadcast-task (lambda () (broadcast-task (lambda ()))))))) + (broadcast-task (lambda () (broadcast-task (lambda ()))))))) + +(full-test bare-task-test + (let ((queue (make-queue :fixed-capacity 1))) + (submit-bare-task (lambda (v) + (sleep 0.5) + (push-queue v queue)) t) + (is (null (try-pop-queue queue :timeout 0))) + (is (try-pop-queue queue :timeout 1)))) (full-test worker-index-test (is (null (kernel-worker-index)))