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

Dmitry Kolesnikov dmkolesnikov@REDACTED
Thu Dec 10 12:37:45 CET 2015


As far I’ve understood the code, Global lock is a variant of Lamport clock implementation.

You can use for that purpose but I’ve never used it for my tasks because it requires message exchange with other cluster nodes. However, some part of OTP platform uses it. If you are aiming a cloud based deployment (e.g. AWS) then better to thing something else. 

Best Regards, 

> On Dec 10, 2015, at 1:16 PM, Roberto Ostinelli <roberto@REDACTED> wrote:
> 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.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list