http://www.perlmonks.org?node_id=1008658


in reply to Re: flock on Windows : process killed while in critical region
in thread flock on Windows : process killed while in critical region

Thanks, I'm relieved - this makes implementation simpler. As for no tight loop polling: I guess a sleep time of a couple of seconds between two calls to flock would not be considered tight anymore, i.e. it would be safe? Currently, we usually sleep between 3 and 12 seconds between polls.

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^3: flock on Windows : process killed while in critical region
by BrowserUk (Patriarch) on Dec 13, 2012 at 12:53 UTC
    I guess a sleep time of a couple of seconds between two calls to flock would not be considered tight anymore, i.e. it would be safe?

    Even half a second or just sleep 0 (which causes the process to relinquish it's current timeslice) will ensure the OS gets processor time to clean up the dying process.

    The situation where things go wrong is when you have multiple processes all polling in tight loops, thus not giving the (lower priority) task of cleaning up the terminating process a look in.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    RIP Neil Armstrong

      On some Windows machines, Sleep 0 (the Win32 C call) has a habit of NOT releasing the time slot for efficiency reasons in the NT kernel to avoid excess context switches and per CPU cache locality (don't move threads or processes between CPUs unless high CPU usage). Sometimes until the timeslot expires (hardware interrupt), Sleep 0 will not release the timeslot and will just spin and the other thread remains frozen and the lock hasn't been released yet so your first thread is spinning in Sleep 0 burning CPU and the process seems deadlocked for many ms.

        Sorry, but unless you link some documentary evidence for that I'm going to say that you are flat-out wrong.

        Sleep( 0 ) has always relinquished the current timeslice of the thread on which it is called, from NT 3.5 upto and including Vista....

        I do not have hands on knowledge of W/7/8, but I can find no evidence to support your premise there either.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        RIP Neil Armstrong