Use umask/0 in test
Avoid race condition in umask/0

Between successive calls to umask/1, the process may be swapped out. If
another process queries the umask, beam may end up in an inconsistent
state. The issue is that querying the umask is destructive: it's done by
setting the umask to 0, then re-setting it back to the original umask.

A better fix would be to put the logic in the NIF where the sequence of
events is atomic. However, it's more fun to experiment with putting the
lock in the Erlang code.

There are 2 potential problems:

1. If another process registers 'perc_umask', umask/0 will spin forever.

2. If something (another NIF, ...) changes the umask between calls,
   umask/0 will crash, releasing the lock. This will kill the calling
   process which may not be expected.

To provoke the race condition:

-module(umask).

-export([stress/1]).

stress(N) ->
    [ spawn(fun() -> set_mask() end) || _ <- lists:seq(1,N) ].

set_mask() ->
    false = 0 == perc:umask(),
    set_mask().