This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Unreliable flock


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]