threads - use them as much as you can

Ulf Wiger etxuwig@REDACTED
Mon Nov 27 17:41:21 CET 2000

On Mon, 27 Nov 2000, Thomas Lindgren wrote:

>A related problem is how to construct a simple, guaranteed read-modify-write
>function on a (public) ets-table, even involving a single location. 
>Is there some way to do that in Erlang without involving mnesia?
>(Needless to say, I've fiddled a bit with this and failed.)

We've suggested a simple mutex lock on the ets table, such that 

ets:mutex(Table, F = fun()) is thread safe, assuming that all
accesses to Table are mutex:ed.

One use for this would be implementing modulo counters based on

A problem of course arises if F doesn't stick to one table. Then you
get into deadlock territory. If you didn't allow nested mutex:es,
you'd be a bit better off. 

Ulf Wiger                                    tfn: +46  8 719 81 95
Senior System Architect                      mob: +46 70 519 81 95
Strategic Product & System Management    ATM Multiservice Networks
Data Backbone & Optical Services Division      Ericsson Telecom AB

More information about the erlang-questions mailing list