Re: [racket-users] Do I need a critical section here ... and if so, how to?

2016-09-01 Thread Greg Hendershott
> 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

Re: [racket-users] Do I need a critical section here ... and if so, how to?

2016-09-01 Thread Robby Findler
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: >

Re: [racket-users] Do I need a critical section here ... and if so, how to?

2016-09-01 Thread David Vanderson
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

Re: [racket-users] Do I need a critical section here ... and if so, how to?

2016-09-01 Thread Erich Rast
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

Re: [racket-users] Do I need a critical section here ... and if so, how to?

2016-09-01 Thread Gustavo Massaccesi
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!

[racket-users] Do I need a critical section here ... and if so, how to?

2016-09-01 Thread Erich Rast
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