<div dir="ltr"><div><div><div><div>A possible interface for thread local variables:<br><br></div>(thread-local-set! key val)<br></div>(thread-local-ref key #!optional (default (macro-absent-obj))) ; when unbound returns default or raises if absent<br><br></div>and thread-cells can be implemented on top with a struct and a gensym.<br><br></div>-- vyzo<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Mar 10, 2018 at 4:16 PM, Dimitris Vyzovitis <span dir="ltr"><<a href="mailto:vyzo@hackzen.org" target="_blank">vyzo@hackzen.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Also, we don't have to follow the plt interface -- we can just call them thread-local-variables :)<br><br></div>-- vyzo<br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Mar 10, 2018 at 3:45 PM, Dimitris Vyzovitis <span dir="ltr"><<a href="mailto:vyzo@hackzen.org" target="_blank">vyzo@hackzen.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div>Marc,<br><br></div>Could we add thread-cells? <br>They can be easily implemented with a per-thread hash-table, that only gets initialized if accessed.<br><br>They are incredibly useful for per thread caches, and probably a lot of other things.<br></div><br>For instance, I have this common pattern that i see a lot:<br><br>(def errptr-cache<br>  (make-hash-table-eq weak-keys: #t))<br>(def errptr-cache-mutex<br>  (make-mutex))<br><br>(def (get-errptr)<br>  (with-lock errptr-cache-mutex<br>    (lambda ()<br>      (cond<br>       ((hash-get errptr-cache (current-thread))<br>        => (lambda (errptr)<br>             (errptr_clear errptr)<br>             errptr))<br>       (else<br>        (let (errptr (check-ptr get-errptr (make_errptr)))<br>          (hash-put! errptr-cache (current-thread) errptr)<br>          errptr))))))<br><br></div>and I would like to eliminate both the lock and the weak table.<br></div></div><div><br></div><div>I can add it and make a pr, but I wanted to consult with you first.<br></div><div><br></div>-- vyzo<br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>