Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multithreading in sbcl

I am newbie at programming in lisp.I am using sbcl.In one part of program thread is created as-

(sb-thread:make-thread
  (lambda ()
    (progn
      (sleep 0)
      (setf c (+ a b))
      (print "ADDITION:")
      (print c))))

I am not getting what lambda() and progn(sleep 0) does, and why it is written inside sb-thread bracket?

like image 246
user3857907 Avatar asked Apr 01 '26 04:04

user3857907


1 Answers

sb-thread:make-thread takes a function to call in a newly created thread.

(lambda ()
   (progn
      (sleep 0)
      (setf c (+ a b))
      (print "ADDITION")
      (print c)))

is an anonymous function. In turn progn creates a program block (un-necessarily in this case, as a lambda body is an implicit progn) and (sleep 0) is probably used as a "please invoke the scheduler here" (it's essentially a no-op, sleeping for 0 seconds).

like image 94
Vatine Avatar answered Apr 02 '26 21:04

Vatine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!