http://qs1969.pair.com?node_id=198170


in reply to File::DumbLock

Please don't use this code.

Please don't give this code your ++ votes.

This code has obvious holes. It is neither functional, nor necessary.

There are ways of executing "atomic" test-and-set operations in every operating system, and this code does not use any of them. This code has windows of vulnerability. It's not a matter of whether or not you'll get burned, but when.

Do not use this code.

-- Randal L. Schwartz, Perl hacker


UPDATE: Hey, to the losers who downvoted this node, next time you get broken in or you can't get your code to work, just remember what you think of expert advice. {sigh} If you don't want me watching your backside, I won't waste my time. I just wish you would have enough guts to tell me to my e-face. Not just -- this node.

And a few people were kind enough to ask me to post references to how it should be done. Most of the first dozen hits I examined by a simple google for "perl lock" were very well written and don't suffer the problems of the code above. I don't think I should need to add instructions about google-ing to every node I write. {sigh}

Replies are listed 'Best First'.
Re: DON'T USE THIS CODE
by boo_radley (Parson) on Sep 16, 2002 at 08:06 UTC

    merlyn sez :

    I don't think I should need to add instructions about google-ing to every node I write. {sigh}
    Ah, but how would they know they were good examples in your opinion?

        So you're saying we need to hear from an objective voice on the subject?
(it's dumb) Re: DON'T USE THIS CODE
by PodMaster (Abbot) on Sep 16, 2002 at 09:47 UTC
    I --ed you.

    I say in pod

    File::DumbLock implements the dumbest kind of "locking" mechanism known to man. It's voluntary, and it can backfire, but virtually every plaform suports it.

    Most of your comments fall apart in face of that statement.

    Flock is not supported on win9x.

    I think people are --ing you because you haven't offered any alternatives, and thus your statements sound smart-alecky.

    I certainly would like to know what

    ways of executing "atomic" test-and-set operations
    are for win9x.

    Are you talking about attempting to create a "lock directory" instead of a lock file (now that I think about it, that's what i'll change it to do)?

    I for one would like to know( i do say above: "If you know of a module that already exists that does this, please /tell me", did I have to also say if you know a better flockless way, tell me?)

    ____________________________________________________
    ** The Third rule of perl club is a statement of fact: pod is sexy.

      Look, your code breaks on every platform. It's dangerous. It will start to spread a bad meme to most of the other platforms, and we don't need that.

      You have not contributed anything to the art. You have only muddied the water.

      perlport says that flock works on Win2K. Hence, the solutions I wrote nearly seven years ago for Unix work fine on Win2K today. The only place this breaks down is on older win95 and win98 releases. For that, your solution offers nothing that works consistently, and even definitely fails because you are performing time-related operations in separate steps, and would be a step backwards for the community at large.

      You have not solved a thing with your post. You have only harmed the community. Thus, I stepped in to try to mark this code as bad as quick as I could.

      -- Randal L. Schwartz, Perl hacker

        Well thank you for helping. You've certainly solved my dilemma.

        Ok, so what do you think of File::FlockDir? (i just ran accross it)

        ____________________________________________________
        ** The Third rule of perl club is a statement of fact: pod is sexy.

      One example strategy could be unlink: you try to delete something and check for the result. If you succeeded, you obtained the lock. This approach makes things more complicated for stale locks...

      Ciao, Valerio

      update: thanks podmaster for the hint.

Re: DON'T USE THIS CODE
by adrianh (Chancellor) on Sep 16, 2002 at 23:40 UTC

    Well. I'm going to buck the trend and agree with merlyn.

    When I first read the node I assumed from the module name that it was mildly-subtle humour on poor locking strategies. Later posts seem to indicate this was not the intention.

    The code has many problems (e.g. not using atomic operations). It needed a warning. I'm glad merlyn made his post. I will ++ it when tomorrows votes roll in.

    That said - just one sentence on why the module was bad (maybe just a reference to 'perldoc -q lock') wouldn't have been too much effort would it :-)

Re: DON'T USE THIS CODE
by ignatz (Vicar) on Sep 16, 2002 at 15:02 UTC
    > I don't think I should need to add instructions about
    > google-ing to every node I write.

    So basically what you are saying is that you don't have to prove anything that you say cause all people have to do is type the right combination of words into google and browse around testing that code for a few hours to see the same thing?

    ()-()
     \"/
      `                                                     
    
      So basically what you are saying is that you don't have to prove anything that you say cause all people have to do is type the right combination of words into google and browse around testing that code for a few hours to see the same thing?
      No.

      But what would you rather I do with the limited time I have here...

      • Write one detailed treatise about why the code at the head of this thread is broken and dangerous?
      • Write five warning postings, leaving others to fill in the blanks if needed?
      I'd rather do the latter, because it innoculates five different diseases instead of just one. Of course, what I'd really rather do is...
      • Write two or three good real postings moving the community forward.
      But as long as people post crap like the beginning of this thread, I don't get to do that.

      It's fundamentally unethical of me to allow bad memes to stand, so as long as I see them, it's my responsibility to point them out. Now, as long as bad memes keep getting posted in this unmoderated forum, my destiny is predetermined. So, either moderate the forum, or let me post-moderate it as I have.

      -- Randal L. Schwartz, Perl hacker

        Back in my days on debate teams we had a term for an argument without proof: it didn't pull. That meant that it carried no weight. Five posts that say something sucks without showing why are five wasted posts in my book.

        People learn a lot more by being shown the why of something than from just being hit upside the head and told not to do it, no matter how experienced the person doing the hitting.

        ()-()
         \"/
          `