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:
parent
f0c0141fe4
commit
51fc066ae2
2 changed files with 9 additions and 5 deletions
|
@ -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
|
done in parallel with that of the other @code{find} call, which can
|
||||||
reduce the execution time of @code{find-prime}.
|
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
|
Guile's futures are implemented on top of POSIX threads
|
||||||
(@pxref{Threads}). Internally, a fixed-size pool of threads is used to
|
(@pxref{Threads}). Internally, a fixed-size pool of threads is used to
|
||||||
evaluate futures, such that offloading the evaluation of an expression
|
evaluate futures, such that offloading the evaluation of an expression
|
||||||
to another thread doesn't incur thread creation costs. By default, the
|
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
|
pool contains one thread per available CPU core, minus one, to account
|
||||||
main thread.
|
for the main thread. The number of available CPU cores is determined
|
||||||
|
using @code{current-processor-count} (@pxref{Processes}).
|
||||||
|
|
||||||
@deffn {Scheme Syntax} future exp
|
@deffn {Scheme Syntax} future exp
|
||||||
Return a future for expression @var{exp}. This is equivalent to:
|
Return a future for expression @var{exp}. This is equivalent to:
|
||||||
|
|
|
@ -146,9 +146,7 @@ touched."
|
||||||
|
|
||||||
(define %worker-count
|
(define %worker-count
|
||||||
(if (provided? 'threads)
|
(if (provided? 'threads)
|
||||||
(if (defined? 'getaffinity)
|
(- (current-processor-count) 1)
|
||||||
(- (bit-count #t (getaffinity (getpid))) 1)
|
|
||||||
3) ;; FIXME: use Gnulib's `nproc' here.
|
|
||||||
0))
|
0))
|
||||||
|
|
||||||
(define %workers
|
(define %workers
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue