[erlang-questions] Understanding global:set_lock/1,2,3

Tobias Schlager <>
Thu Dec 10 13:55:36 CET 2015


Hi Roberto,

AFAIK for the user global locks work similar to other mutex/lock implementation, in your case {?MODULE, lock_mnesia_for_a_while} is your 'mutex'. Locking this mutex does not automagically lock mnesia or guard shared data structures. However, a second process trying to aquire/lock the mutex will be blocked until the current owner releases the lock.

Please correct me if I'm wrong.

Regards
Tobias

________________________________
Von:  []" im Auftrag von "Roberto Ostinelli []
Gesendet: Donnerstag, 10. Dezember 2015 12:16
An: Erlang
Betreff: [erlang-questions] Understanding global:set_lock/1,2,3

Dear list,
I'm trying to get an understanding of what global:set_lock/1,2,3 exactly does.

I read from the docs:
Sets a lock on the specified nodes (or on all nodes if none are specified) on ResourceId for LockRequesterId.

Let's say that I want to perform a series of operations on mnesia schemas and want to avoid all other nodes accessing mnesia tables while one node is busy at it.

Is it enough to write:

global:trans({{?MODULE, lock_mnesia_for_a_while}, self()},
    fun() ->
        do_things_on_mnesia()
    end).

I don't get how this could lock mnesia for the other nodes.

Can some kind soul point me in the right direction?

Thank you,
r.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20151210/032b1439/attachment.htm>


More information about the erlang-questions mailing list