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 need to
ensure that every thread gets a unique handle. However, the handles need
not reflect the temporal order of the calling sequence in any way. It's
hard to debug but I believe I've seen a case in which the above code
has assigned the same handle to concurrent threads, as one would expect.

So basically new-handle needs to be in a critical section, right? I feel
stupid that I don't know the answer, but how do I do this?

In the docs I've found ffi/unsafe/atomic, but this seems like overkill
and is unsafe and only intended for the FFI.

Second question: Should I use a parameter or something else for this
construct, and if so, what are the benefits of doing so? What would be
the 'right' way of providing unique numbers in a synchronized way?

Best,

Erich

-- 
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 racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to