George Russell wrote:
> The problem is that lowerFlags should appear to be atomic, so that
> if lowerFlags is called simultaneously in different threads, the result
> should be the same as if one of the calls completed before the other started.

If you want lowerFlags to be atomic, in the global sense, then you
really have no other option than to create a "global" variable (read:
unsafePerformIO). Intuitively, this make sense: if some thread needs to
know whether or not it has permission to perform lowerFlags, then there
must be some sort of common mutex with which to communicate with the
other threads. Depending on your situation, this common mutex could
perhaps exist in a closure.

However, I believe that you can be "reasonably" atomic without a global
variable. That is, if two or more lowerFlags calls are called with the
same Flag value, they will execute serially. I haven't thought enough
about it to come up with a concrete solution. If this is good enough,
I'll see if I can noodle on it some more.

- Michael Hobbs

Reply via email to