Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Ways to sequence calls from multiple processes

by Eyck (Priest)
on Nov 29, 2004 at 06:57 UTC ( [id://410872]=note: print w/replies, xml ) Need Help??


in reply to Ways to sequence calls from multiple processes

Why not use IPC - semaphores, isn't it what they were created for? (Serializing access to limited resources?).
use IPC::SysV qw(IPC_PRIVATE S_IRWXU IPC_CREAT); use IPC::Semaphore; $sem = new IPC::Semaphore(IPC_PRIVATE, 10, S_IRWXU | IPC_CREAT); # and the crucial part: $sem->op($semaphoreNumber,0,0); # where first zero means wait-for-zero operation, # ie, your code will stop and wait (CPU-friendly) # until your semaphore becomes 0. #etc...

Why hasn't anyone suggested this yet?

This is a SolvedProblem(TM) in computer sciences, ...or maybe I'm missing something?

OTOH, I find spool-model generally more usefull, ie - you've got dedicated process for processing incoming jobs, and your workers just drop their jobs into a spool, be it directory, sql table or shared memory segment (I would recommend IPC::ShareLite).

This is the way mail servers, fax srvrs and many others work...

Why is everyone soo keen on using files when there are superior methods around? When it goes to synchronising jobs between multiple machines files are not that great either, you get multiple problems with most remote filesystems... on the other hand there are remote IPC solutions available and they are created and tested specifically to work with such scenarios.

I don't know if this is the case, but I usually have such feelings when interfacing with php/mysql people... they have no CS background or are unable to use it...ask the simplest questions about the basic things... and then proceed to solve them with strangest hoops... and THEN they warp the reality with their weight and make young programmers think that this is the right solution.

Replies are listed 'Best First'.
Re^2: Ways to sequence calls from multiple processes
by Anonymous Monk on Nov 29, 2004 at 21:21 UTC
    To address your question, file locking is preferred because flock() semantics have been more portable than SysV IPC, historically, among unix-like systems. Also the system semaphore count, in some OS flavors, was set with a kernel configuration parameter, and required admin management. Filehandles were relatively cheap, in terms of allocatable resources, and can be got without bothering the SA. However, when dealing with reasonably up to date and homogeneous systems, your answer is of course prefereable.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://410872]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-23 21:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found