File tree 2 files changed +39
-3
lines changed
2 files changed +39
-3
lines changed Original file line number Diff line number Diff line change 91
91
; ; Ensure correct results are returned by multi-threaded task-map
92
92
; ; (in any order).
93
93
(mapc (lambda (result) (is (member result results))) ' (2 3 4 ))))
94
+
95
+ (defvar *in-worker* )
96
+
97
+ (deftest test-worker-env ()
98
+ " Using `*worker-funcall*' should change the environment of tasks
99
+ launched directly as well as tasks launched from the task thread."
100
+ (is (not (boundp ' *in-worker*)))
101
+ (let* ((thread-count 4 )
102
+ (worker-fn
103
+ (lambda (fn)
104
+ (let ((*in-worker* t ))
105
+ (funcall fn))))
106
+ (*worker-funcall* worker-fn)
107
+ boundp )
108
+ (task-map thread-count
109
+ (lambda (x)
110
+ (declare (ignore x))
111
+ (synchronized (' boundp)
112
+ (push (boundp ' *in-worker*) boundp ))
113
+ (task-map thread-count
114
+ (lambda (x)
115
+ (declare (ignore x))
116
+ (synchronized (' boundp)
117
+ (push (boundp ' *in-worker*) boundp )))
118
+ (make-list thread-count)))
119
+ (make-list thread-count))
120
+ (is (every (eqls t ) boundp ))))
Original file line number Diff line number Diff line change 114
114
(:export
115
115
:task-runner
116
116
:*task-runner*
117
+ :*worker-funcall*
117
118
:task-runner-jobs
118
119
:task-runner-workers
119
120
:task-runner-workers-count
164
165
(defparameter *task-runner* nil
165
166
" Bind *TASK-RUNNER* for worker threads" )
166
167
168
+ (defparameter *worker-funcall* #' funcall
169
+ " Function that invokes worker loop to run.
170
+ When this value is bound when starting a task, the value is propagated
171
+ through to any further tasks launched from the first task, and so on." )
172
+
167
173
(defclass task ()
168
174
((object :initarg :object :accessor task-object))
169
175
(:documentation " Base class for all task classes." ))
274
280
(defun task-runner-create-worker (runner)
275
281
" Create a new worker thread."
276
282
(let ((*default-special-bindings*
277
- (acons ' *task-runner* runner
278
- *default-special-bindings* )))
283
+ (list* (cons ' *task-runner* runner)
284
+ (cons ' *worker-funcall* *worker-funcall* )
285
+ *default-special-bindings* )))
279
286
(with-lock-held ((task-runner-workers-lock runner))
280
- (push (make-thread ' start-worker
287
+ (push (make-thread
288
+ (lambda ()
289
+ (funcall *worker-funcall* #' start-worker))
281
290
:name (format nil " ~A -~D " " software-mutator"
282
291
(incf worker-id)))
283
292
(task-runner-workers runner))))))
You can’t perform that action at this time.
0 commit comments