All Manuals > KnowledgeWorks and Prolog User Guide > 6 Advanced Topics > 6.5 Inferencing States > 6.5.3 Uses of Inferencing States

NextPrevUpTopContentsIndex

6.5.3.1 Multiple threads

By binding *inferencing-state* around all KnowledgeWorks operations in a thread's main function as in the example below, its value can be unique to each thread.

(defun test-1-counter (name)
  (let* ((*inferencing-state* nil)
         (step (1+ (random 10)))
         (limit (* step (+ 2000 (random 100)))))
    (unwind-protect
        (progn
          (setq *inferencing-state*
                (make-inferencing-state name))
          (make-instance 'counter
                         :value limit
                         :step step)
          (infer))
      (destroy-inferencing-state *inferencing-state*))))
 
(mp:process-run-function (format nil "Test ~D" index)
                         '()
                         'test-1-counter
                         (gensym)

KnowledgeWorks and Prolog User Guide (Unix version) - 6 Dec 2011

NextPrevUpTopContentsIndex