CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Mutex in perl

 



harinarayana
New User

Dec 17, 2013, 4:38 AM

Post #1 of 5 (13340 views)
Mutex in perl Can't Post

I want to lock some code in perl script using mutex semaphore,Could you please help with some example how to initialize,lock and unlock the mutex.


FishMonger
Veteran / Moderator

Dec 17, 2013, 6:13 AM

Post #2 of 5 (13333 views)
Re: [harinarayana] Mutex in perl [In reply to] Can't Post

What do you mean by "lock some code in perl script"?

have you looked at any of the mutex or semaphore related modules on cpan?
http://search.cpan.org/search?query=mutex&mode=all
http://search.cpan.org/search?query=semaphore&mode=all


harinarayana
New User

Dec 18, 2013, 6:22 AM

Post #3 of 5 (13224 views)
Re: [FishMonger] Mutex in perl [In reply to] Can't Post

Actually I have a Perl script,In that i need to run some part of the code by single user at a time.Please see the example below.

Eg:
code...
.......
MUTEX LOCK
performTask();
MUTEX UNLOCK.
......
..........


(This post was edited by FishMonger on Dec 18, 2013, 6:51 AM)


FishMonger
Veteran / Moderator

Dec 18, 2013, 6:52 AM

Post #4 of 5 (13216 views)
Re: [harinarayana] Mutex in perl [In reply to] Can't Post

You need to provide more details on what your script is doing, how it's run and what the performTask() sub does.


FishMonger
Veteran / Moderator

Dec 18, 2013, 7:51 AM

Post #5 of 5 (13209 views)
Re: [harinarayana] Mutex in perl [In reply to] Can't Post

Based on the limited info you've given so far, my suggestion would be to modify the performTask() sub. The first thing it needs to do is check if a lock file (i.e. semaphore/mutex file) is already created. If it is, either exit or wait depending on your needs. If it hasn't been created, then the sub will create it and continue doing its work. The last thing the sub should do is remove the lock file so that the next process can do its work.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives