Re: Inconsistent loop behaviour when using threads.
Lubwama Abdul Muswawir <[email protected]> Wed, 23 Apr 2025 13:59:33 +0000
| Newsgroups | gmane.lisp.steel-bank.general |
|---|---|
| Message-ID | <[email protected]> |
Thank you,Muswawir.Regards,Lubwama Abdul Muswawir,Founder,Ninx Technology Limited,Wakiso, Uganda.Home | AboutRobert Smith wrote:instead do(loop for i from 0 to 1000 do (make-thread (let ((i i)) (lambda ...))))LOOP may mutate the variable i, and that same variable is being captured by all of your lambdas. Therefore, bind a fresh lexical variable (of the same name) so each lambda gets its own binding.Robert On Wed, Apr 23, 2025 at 06:13 Lubwama Abdul Muswawir <[email protected]> wrote:Hi, I am currently exploring the actor concurrent models in SBCL. The loop macro is behaving wierdly when using threads inside it. Example loop:```(eval-when (:compile-toplevel) (defun test-p () (loop for i from 0 to 1000 do (make-thread (lambda () (format #.*terminal-io* "Working on: ~a~%" i))))))```This will print from 1 to 1001, it will work within expected bounds when I use dolist, when I don't use threads. My use case involves using threads on a range which I intended to generate via loop. This behaviour is consistent with all actor packages (sento, lisp-actors) I have tried because all use sb-thread. _______________________________________________ Sbcl-help mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sbcl-help _______________________________________________ Sbcl-help mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sbcl-help