Sorry I wasn't clear about that. The lock is not global, it is per cache. newCache creates a newMVar which serves as the thread safe lock for that cache.
Concurrently fetching from different caches can indeed run their separate fallbacks concurrently.
Hi Dan,
> 1. Create an empty cache with newCache
> 2. fetch repeatedly from the cache, each time providing a fallback in
> case it is empty.
>
> Fetching from a Cache is thread safe: only one "fallback" will execute
> at a time, and after the first successful fallback, the cached value
> will be set and no other fallbacks will be called.
I'm not sure whether I get this correctly. If multiple threads fetch
values from one cache, will only one of those threads run at a time? Or
will those that fetch pairwise different values still run concurrently?
In other words, does the cache have a global lock or is there a lock per
value?
Best regards,
Peter
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe