public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Unreliable flock
@ 2016-04-02 21:35 Andrey Repin
  2016-04-04 15:16 ` Corinna Vinschen
  0 siblings, 1 reply; 7+ messages in thread
From: Andrey Repin @ 2016-04-02 21:35 UTC (permalink / raw)
  To: All

Greetings, All!

The script (let's call it test.sh):

#!/bin/dash -x
_lock="./console-session.lock"
{
  flock -n 9 || {
      echo "The $(cat "$_lock") command is running already."
      exit 3
    } >&2

  printf "$1" >&9

  trap 'rm "$_lock";' EXIT HUP INT ABRT TERM

  sleep 20

} 9>> "$_lock"

Very simple in essence.
The one-liner:

{ flock -n 9 && sleep 10 || echo Fail;} 9>> ./console-session.lock

Also extremely simple.

Open two terminals. mintty or native, bash or dash, doesn't matter.
chdir to the directory with the script.

Start script in one terminal. ./test.sh
Start oneliner in another terminal. Fail. How predictable!

Wait till both expire.
Now start oneliner first.
Then script.
Both succeed. Not 100% but highly, highly probable. Sometimes it even work
both ways.

At the same time, I can't reproduce it on Linux at all.
But I do can reproduce it on Cygwin. Both 32 and 64 bit. With both dash and
bash. With both local and remote FS.

CYGWIN_NT-5.1 foserver 2.4.1(0.293/5/3) 2016-01-24 11:24 i686 Cygwin
CYGWIN_NT-6.1 daemon2 2.4.1(0.293/5/3) 2016-01-24 11:26 x86_64 Cygwin
CYGWIN_NT-6.1 buildbotw7 2.4.1(0.293/5/3) 2016-01-24 11:26 x86_64 Cygwin


-- 
With best regards,
Andrey Repin
Saturday, April 2, 2016 23:22:25

Sorry for my terrible english...


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-04-05  8:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-02 21:35 Unreliable flock Andrey Repin
2016-04-04 15:16 ` Corinna Vinschen
2016-04-04 17:05   ` Andrey Repin
2016-04-04 19:06     ` Corinna Vinschen
2016-04-05  2:20       ` Andrey Repin
2016-04-05  8:33         ` Corinna Vinschen
2016-04-04 19:24     ` Warren Young

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).