"be consistent" | |
PerlMonks |
Re: any module with streaming pipe implementation for use with threadsby mr.nick (Chaplain) |
on Dec 20, 2011 at 19:38 UTC ( [id://944454]=note: print w/replies, xml ) | Need Help?? |
Hi Rohan,
I haven't used threads in quite a while now, but after reading through your code I do have a couple comments/observations to make. Take them with a grain of salt. First of all, are you absolutely certain that you need to roll your own shared stack? Other than controlling the size of the stack, and your 'phases', it looks to me like you could do the same using threads::shared. In fact, it looks like you started that approach. It may be that you are overengineering the project. Secondly, I don't believe your communication object, $pipe1, is going to be shared between the two threads. If I recall my perl threading model, each thread receive a copy of the interpreter, with data as-of the creation of the thread. Once that split has been done, they don't share any relationship with each other. Here's something that I whipped up real fast. No doubt the locking mechanism isn't correct, but maybe it'll point you towards the correct location:
I can see a few issues with my code, especially if there are multiple getters and putters running at the same time. But you can serialize those operations, in a very brute force kind of way, but creating some shared scalars (eg: $get_in_progress) and locking those.
Edit: changed code to do a little more work. mr.nick ...
In Section
Seekers of Perl Wisdom
|
|