Hi Dominic

Thanks very much for your prompt reply.

Your response works very well.

I didn’t know there is a distinction between semaphores and fsemaphores.

You have helped me a lot.

Thanks again, Jos

 

 

 

From: Dominik Pantůček
Sent: viernes, 12 de noviembre de 2021 18:59
To: [email protected]
Subject: Re: [racket-users] future question

 

Hi,

 

you are looking for make-fsempahore[1] and related:

 

===

#lang racket

 

(define sema (make-fsemaphore 1))

 

(define (make-th i)

 

(λ ()

   (let loop ((a 0))

(when (zero? (modulo a #e1e6))

     (fsemaphore-wait sema)

     "do what you have to do without disturbing other futures"

     (fsemaphore-post sema))

    (loop (add1 a)))))

(for ((i (in-range (processor-count)))) (future (make-th i)))

(sleep 10)

(exit)

===

 

The above updated source spins all your cores just fine.

 

 

Cheers,

Dominik

[1]

https://docs.racket-lang.org/reference/futures.html#%28part._.Future_.Semaphores%29

 

 

On 12. 11. 21 18:44, Jacob Jozef wrote:

> #lang racket

>

> (define sema (make-semaphore 1))

>

> (define (make-th i)

>

> (λ ()

>

>    (let loop ((a 0))

>

> #;(when (zero? (modulo a #e1e6))

>

>      (semaphore-wait sema)

>

>      "do what you have to do without disturbing other futures"

>

>      (semaphore-post sema))

>

>     (loop (add1 a)))))

>

> (for ((i (in-range (processor-count)))) (future (make-th i)))

>

> (sleep 10)

>

> (exit)

>

 

--

You received this message because you are subscribed to the Google Groups "Racket Users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/cc8c5754-9354-6367-7c62-b8c12cb60cd4%40trustica.cz.

 

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/3150F731-CB07-4078-9044-755ACDFE13DC%40hxcore.ol.

Reply via email to