1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

Use `current-processor-count' to determine the number of future-workers.

* module/ice-9/futures.scm (%worker-count): Use
  `current-processor-count'.

* doc/ref/api-scheduling.texi (Futures): Add note about side-effects and
  I/O.  Mention `current-processor-count'.
This commit is contained in:
Ludovic Courtès 2010-12-07 23:11:53 +01:00
parent f0c0141fe4
commit 51fc066ae2
2 changed files with 9 additions and 5 deletions

View file

@ -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:

View file

@ -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