[gambit-list] thread-cells?

Dimitris Vyzovitis vyzo at hackzen.org
Sat Mar 10 09:16:10 EST 2018


Also, we don't have to follow the plt interface -- we can just call them
thread-local-variables :)

-- vyzo

On Sat, Mar 10, 2018 at 3:45 PM, Dimitris Vyzovitis <vyzo at hackzen.org>
wrote:

> Marc,
>
> Could we add thread-cells?
> They can be easily implemented with a per-thread hash-table, that only
> gets initialized if accessed.
>
> They are incredibly useful for per thread caches, and probably a lot of
> other things.
>
> For instance, I have this common pattern that i see a lot:
>
> (def errptr-cache
>   (make-hash-table-eq weak-keys: #t))
> (def errptr-cache-mutex
>   (make-mutex))
>
> (def (get-errptr)
>   (with-lock errptr-cache-mutex
>     (lambda ()
>       (cond
>        ((hash-get errptr-cache (current-thread))
>         => (lambda (errptr)
>              (errptr_clear errptr)
>              errptr))
>        (else
>         (let (errptr (check-ptr get-errptr (make_errptr)))
>           (hash-put! errptr-cache (current-thread) errptr)
>           errptr))))))
>
> and I would like to eliminate both the lock and the weak table.
>
> I can add it and make a pr, but I wanted to consult with you first.
>
> -- vyzo
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20180310/09855fd8/attachment.htm>


More information about the Gambit-list mailing list