[racket] future on dual processor machine
The program below has strange behaviour:
I run it from DrScheme on a dual core machine with two processors.
No other applications active.
When I run it the first time it uses 100% of both processors.
Running it again without leaving DrScheme, it apparently uses one processor
at a time only, although switching frequently. CPU usage histories mirror
each other. How come only one processor is used at a time during the second
run?
Leaving DrScheme, restarting DrScheme and running again gives me 100% of
both processors again.
In all runs processor-count returns 2.
Thanks, Jos
DrRacket, version 5.1.1.5--2011-05-09(b74c9f9/a) [3m].
Windows 7.
Intel Pentium dual core CPU E6500.
#lang racket
; check that both processors are used by means of
; windows tool for measurement of CPU usage.
(require racket/unsafe/ops)
(require racket/fixnum)
(require racket/future)
(collect-garbage)
(processor-count) ; -> 2
(define N/2 #e1e8)
(define N (* 2 N/2))
(define V (make-fxvector N))
(define (set-V! f r) (unsafe-fxvector-set! V f r))
(define (task1)
(for ((i (in-range 50)))
(for ((k (in-range 0 N/2))) (set-V! k k))))
(define (task2)
(for ((i (in-range 50)))
(for ((k (in-range N/2 N))) (set-V! k k))))
; task1 fills the first half of vector V.
; task2 the second half.
; In both tasks the ((i (in-range 50))) is inserted in order to
; force the program to run long enough to see its parallel effects.
(define f (future task1))
(task2)
(touch f)
; Clear memory avoiding memory overflow during next run.
(set! V #f)
(set! f #f)
(collect-garbage)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110516/4edbda6f/attachment.html>