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

Roberto Ostinelli <>
Fri Dec 11 11:33:54 CET 2015


Hi Dmitry and Tobias,
Yes - it looks like these are simple mutex.

Thank you for your inputs!
r.

On Thu, Dec 10, 2015 at 1:55 PM, Tobias Schlager <
> wrote:

> 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/20151211/1659fa8c/attachment.html>


More information about the erlang-questions mailing list