如何在LISP中设置线程的优先级?

时间:2015-04-23 16:24:14

标签: multithreading common-lisp

(defvar firstnumber)
(defvar secondnumber)
(defvar length1)
(defvar mulb)
(defvar var1)
(defvar num1)
(defvar num2)
(defvar addition)
(defvar subs)
(defvar muls)
(defvar divs)

(defun acceptnumber()
    (write-line "Enter the first number:")
    (force-output t)
    (setf firstnumber(read))
    (write-line "Enter the second number:")
    (force-output t)
    (setf secondnumber(read))
    (setf length1(integer-length secondnumber))
)

(defun add(num1 num2)
    (setf addition(+ num1 num2))
    (write-line "Addition of two numbers:")
    (write addition)
    (write-line " " )
)

(defun sub(num1 num2)
    (setf subs(- num1 num2))
    (write-line "Substraction of two numbers:")
    (write subs)
    (write-line " ")

)
(defun mul(num1 num2)
    (setf muls(* num1 num2))
    (write-line "Multiplication of two numbers:")
    (write muls)
    (write-line " ")
)
(defun div(num1 num2)
    (setf divs(/ num1 num2))
    (write-line "Division of two numbers:")
    (write divs)
    (write-line " ")
)

(defun binarymul(num1 num2)

    (setf mulb 0)

    (
        loop for i from 1 to length1 do 
        (
            if(= 1 (logand num2 1))
            (setf mulb(+ mulb num1))
        )

    (setf num2(ash num2 -1))    
    (setf num1(ash num1 1))

    )
(write-line "Binary Multiplication ::")
(write mulb)
(write-line " ")
(write-line "In binary form::")
(setf var1(format nil "~B" mulb ))
(write-line var1)
)





(acceptnumber)
(sb-thread:make-thread(lambda()(binarymul firstnumber secondnumber)))
(sb-thread:make-thread(lambda()(add firstnumber secondnumber)))
(sb-thread:make-thread(lambda()(sub firstnumber secondnumber)))
(sb-thread:make-thread(lambda()(mul firstnumber secondnumber)))
(sb-thread:make-thread(lambda()(div firstnumber secondnumber)))

我开始学习LISP并发编程。我用sb-thread编写了一个简单的计算程序。现在我想为每个线程设置优先级。例如设置优先级更高的ti binarymul函数等。 我可以设置sb-thread的优先级吗?如果是,如何?

1 个答案:

答案 0 :(得分:0)

SBCL的手册说(重点补充):

  

12 Threading

     

SBCL支持映射到的相当低级别的线程接口   主机操作系统的线程或轻量级概念   流程。这意味着线程可以利用硬件   在具有多个CPU的计算机上进行多处理,但确实如此   不允许Lisp控制调度程序。这可以在   SB-THREAD包。

认为线程优先级通常需要对调度程序进行一些访问,因此您无法使用SBCL设置线程优先级。