parallel-constructs.scm 783 B

12345678910111213141516171819202122232425262728293031
  1. (use-modules (ice-9 threads))
  2. (define (busy-work limit)
  3. (if (> limit 0)
  4. (begin (sqrt (+ (expt limit limit) 1))
  5. (busy-work (- limit 1)))
  6. 'done))
  7. (define (displayln something)
  8. (display something)
  9. (newline))
  10. (let ((limit 1000))
  11. (display
  12. ;; to use multiple values one can use `call-with-values`.
  13. (call-with-values
  14. (lambda () (parallel (busy-work 1000)
  15. (busy-work 1000)))
  16. (lambda (a b) (displayln (list a b))))))
  17. ;; You can also use receive to create the bindings.
  18. (use-modules (ice-9 receive))
  19. (let ((limit 1000))
  20. (display
  21. ;; to use multiple values one can use `receive`.
  22. (receive (range1 range2)
  23. (parallel (busy-work 1000)
  24. (busy-work 1000))
  25. (list range1 range2))))