<div dir="ltr"><div>Ok, I hadn't thought of that.<br></div><div><br></div><div>-- vyzo<br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 12, 2018 at 6:34 PM, Marc Feeley <span dir="ltr"><<a href="mailto:feeley@iro.umontreal.ca" target="_blank">feeley@iro.umontreal.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Extensions to Gambit threads can be done currently using the define-type-of-thread special form.  For example:<br>
<br>
(define-type-of-thread mythread<br>
  constructor: construct-mythread<br>
  errptr)<br>
<br>
(define (make-mythread thunk)<br>
  (thread-init!<br>
   (construct-mythread #f)<br>
   thunk))<br>
<br>
(define t<br>
  (make-mythread<br>
   (lambda ()<br>
     (pp (mythread-errptr (current-thread))))))<br>
<br>
(mythread-errptr-set! t 'foo)<br>
<br>
(thread-start! t)<br>
<br>
(thread-join! t)<br>
<br>
So I don’t see the need for adding this feature to the basic Gambit threads.<br>
<span class="HOEnZb"><font color="#888888"><br>
Marc<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
> On Mar 10, 2018, at 8:45 AM, Dimitris Vyzovitis <<a href="mailto:vyzo@hackzen.org">vyzo@hackzen.org</a>> wrote:<br>
><br>
> Marc,<br>
><br>
> 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>
><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>
> and I would like to eliminate both the lock and the weak table.<br>
><br>
> I can add it and make a pr, but I wanted to consult with you first.<br>
><br>
> -- vyzo<br>
<br>
</div></div></blockquote></div><br></div>