diff --git a/doc/ref/api-scheduling.texi b/doc/ref/api-scheduling.texi index 28e90e3d1..d202f4a69 100644 --- a/doc/ref/api-scheduling.texi +++ b/doc/ref/api-scheduling.texi @@ -848,12 +848,18 @@ machine, though, the computation of @code{(find prime? lst2)} may be done in parallel with that of the other @code{find} call, which can reduce the execution time of @code{find-prime}. +Note that futures are intended for the evaluation of purely functional +expressions. Expressions that have side-effects or rely on I/O may +require additional care, such as explicit synchronization +(@pxref{Mutexes and Condition Variables}). + Guile's futures are implemented on top of POSIX threads (@pxref{Threads}). Internally, a fixed-size pool of threads is used to evaluate futures, such that offloading the evaluation of an expression to another thread doesn't incur thread creation costs. By default, the -pool contains one thread per CPU core, minus one, to account for the -main thread. +pool contains one thread per available CPU core, minus one, to account +for the main thread. The number of available CPU cores is determined +using @code{current-processor-count} (@pxref{Processes}). @deffn {Scheme Syntax} future exp Return a future for expression @var{exp}. This is equivalent to: diff --git a/module/ice-9/futures.scm b/module/ice-9/futures.scm index b2e4c0da5..1e9247dce 100644 --- a/module/ice-9/futures.scm +++ b/module/ice-9/futures.scm @@ -146,9 +146,7 @@ touched." (define %worker-count (if (provided? 'threads) - (if (defined? 'getaffinity) - (- (bit-count #t (getaffinity (getpid))) 1) - 3) ;; FIXME: use Gnulib's `nproc' here. + (- (current-processor-count) 1) 0)) (define %workers