Re: semaphores
[email protected] (Uri Guttman)
| Newsgroups | perl.loop |
|---|---|
| Message-ID | <[email protected].> |
>>>>> "JNP" == Joshua N Pritikin <[email protected]> writes: JNP> It turned out that semaphores were easier than I expected. Now JNP> that I understand them, I'm even more skeptical that they belong JNP> in Event. I'm not saying that I would reject an implementation, JNP> but they seem like too specialized a mechanism for commonplace JNP> Event'ing. here's my take on semaphores along with the pound of salt it needs on the side. i have (almost?) never used true semaphores in many years of coding event systems. i discovered that pipes make for very effective semaphores even in a threaded system. the advantage was that i could use select/poll on those pipes where i couldn't with semaphores. my view is semaphores are used for sharing some resource between processes/threads. most designs block on the semaphores as they have many threads doing other work in the mean time. with an event system that won't work as well especially in perl with only experimental threads (so use processes instead). the only way semaphores would make sense in an event system is for the semaphore to trigger some event when the other side has counted it down to zero (or however the semaphore is designed). the problem is that normally you may have multiple things blocking on the semaphore and they all get woken up and the first to get the semaphore wins. how do you translate that to callbacks? and i don't think semaphores have any way to wakeup a process in a select/poll blocking state which is even more critical in an event loop (maybe there is a signal?). so the other side will have to count down the semaphore AND do something to wake up the other side. hence my liking of pipes which can do both (un/locking a resource and triggering an event) at the same time. so i don't feel semaphores need to be supported in event.pm as their use can be emulated easily with pipes/sockets. now drink soem water to handle the many grains of salt i sprinkled over that message. :-) uri -- Uri Guttman --------- [email protected] ---------- http://www.sysarch.com SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books The Best Search Engine on the Net ---------- http://www.northernlight.com