[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Thread safe hash tables?

From: Reed Sheridan
Subject: Re: [Chicken-users] Thread safe hash tables?
Date: Sun, 5 Mar 2006 04:50:22 -0600

> so you think I can mess up the internal data structure of a hash table if
I access it concurrently from two threads? That's nasty. I'll have to put
a bazillion of those
       (lambda () (mutex-lock! some-hash-mtx))
       (lambda () (do-something-to (mutex-specifix some-hash-mtx)))
       (lambda () (mutex-unlock! some-hash-mtx)))
blocks into my code. But thank you for telling me, because after some
tests I thought the hash tables *were* thread safe.


Why not just do something like:

(define (make-locking-hash-table)
  (cons (make-mutex) (make-hash-table)))

(define (locking-hash-table-set! lht . args)
      (lambda () (mutex-lock! (car lht)))
      (lambda () (apply hash-table-set! (cdr lht) args ))
      (lambda () ...unlock it)))

That seems better than using bazillions of dynamic-winds to me.

Reed Sheridan

reply via email to

[Prev in Thread] Current Thread [Next in Thread]