Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add execute-task to execute task and discard return value #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/kernel/core.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 2 additions & 0 deletions src/kernel/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
(:export #:make-channel
#:submit-task
#:broadcast-task
#:submit-bare-task
#:bare-task
#:submit-timeout
#:cancel-timeout
#:receive-result
Expand Down
10 changes: 9 additions & 1 deletion test/kernel-test.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down