In the ongoing quest to make all my code run on Windows properly, most of the biggest problems are now solved, at least for my stuff.
But one obvious bug-bear remains, file locking.
File locking is already a bit of a pain, even on Unix. Extend that across all platforms and it becomes horrid.
For example, one of my favourite tricks for (mostly non-cpan) scripts that should only ever run one instance is the DATA lock.
In short, you add a small __DATA__ section to the end of your launch script, and then flock the resulting DATA file-handle.
This works brilliantly, because it relies on the existence of nothing other than the script itself, and the lock automatically cleans up when the script ends, crashes, or the power goes out, etc etc. In my experience of using it, it's the only 100% reliable locking scheme.
But of course it doesn't work on Windows...
And I've never seen any really good locking schemes that worked cross-platform. CPAN.pm's locking method for example is a continuous nightmare of unreliable and stale lock files.
So is there an answer out there that is both completely reliable, works everywhere, and doesn't involve me rolling my own.
What do you use?