> What about box-cas! ?
You might find it handy to use box-cas! via a "swap" style wrapper,
such as box-swap! from rackjure/utils:
(define (box-swap! box f . args)
(let loop ()
(let* ([old (unbox box)]
[new (apply f old args)])
(if (box-cas! box old new)
new
If you use thread cells you can avoid global state and synchronization
entirely to solve this problem. Just put a list in the thread cell and add
elements for children threads and increment the head element when new
threads are created.
Robby
On Thursday, September 1, 2016, Erich Rast wrote:
>
Did you look at using a semaphore? That's what I would try, but I also
didn't know about box-cas!
Thanks,
Dave
On 09/01/2016 10:49 AM, Erich Rast wrote:
Wow, I didn't know about box-cas! That seems to be a good solution in
this case. Thanks!
-- Erich
On Thu, 1 Sep 2016 09:37:06 -0300
Gust
Wow, I didn't know about box-cas! That seems to be a good solution in
this case. Thanks!
-- Erich
On Thu, 1 Sep 2016 09:37:06 -0300
Gustavo Massaccesi wrote:
> What about box-cas! ?
> https://docs.racket-lang.org/reference/boxes.html#%28def._%28%28quote._~23~25kernel%29._box-cas%21%29%29
>
> S
What about box-cas! ?
https://docs.racket-lang.org/reference/boxes.html#%28def._%28%28quote._~23~25kernel%29._box-cas%21%29%29
Something like:
;---
#lang racket
(define handle-counter (box 1))
(define (new-handle)
(define old (unbox handle-counter))
(define new (add1 old))
(unless (box-cas!
This question is also about style. Take an admittedly ugly
counter like this
;; increasing counter for handles
(define handle-counter 1)
(define (new-handle)
(begin0
handle-counter
(set! handle-counter (add1 handle-counter
Various threads may call (new-handle) concurrently, so I ne
6 matches
Mail list logo