<div dir="ltr">Interesting. Great addition to thread-specific.<div class="gmail_extra"><br><div class="gmail_quote">2018-03-13 0:34 GMT+08:00 Marc Feeley <span dir="ltr"><<a href="mailto:feeley@iro.umontreal.ca" target="_blank">feeley@iro.umontreal.ca</a>></span>:<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>
<br>
Marc<br>
<div><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>______________________________<wbr>_________________<br>
Gambit-list mailing list<br>
<a href="mailto:Gambit-list@iro.umontreal.ca">Gambit-list@iro.umontreal.ca</a><br>
<a href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list" rel="noreferrer" target="_blank">https://webmail.iro.umontreal.<wbr>ca/mailman/listinfo/gambit-<wbr>list</a><br>
</blockquote></div><br></div></div>