SimonPratt has asked for the wisdom of the Perl Monks concerning the following question:
Hi, Monks
Not really sure where to start with this issue, so I'll try and describe it as best I can and see whether anyone has heard of anything like this before. Please bear with me and let me know if I can provide any further details.
I'm building an OO based communication system utilising Microsoft MSMQ and multithreaded Perl v 5.16.2
The design uses one thread to receive message alerts from MSMQ and queue the message ID numbers for multiple separate worker threads to work on. I'm using threads to create the threads and Thread::Queue to control the queues internal to Perl. The worker thread creates an object representing the open MSMQ queue, then listens to the Thread::Queue for message ID numbers. When an ID comes in, it assigns the ID to the MSMQ object and requests the MSMQ message to be returned.
The problem occurs when I retrieve the message ID from the Thread::Queue, pass it directly to the MSMQ object and ask for the message - Nothing comes back. If I add a print statement to print out the message ID before requesting the message from the MSMQ object, everything works perfectly.
Works:
while($$queueObject{msmqLookupId} = $$self->{queue}->dequeue()) { print "$$queueObject{msmqLookupId}\n"; &{$$self->{handler}}($queueObject->peekMessage()); }
Doesn't work:
while($$queueObject{msmqLookupId} = $$self->{queue}->dequeue()) { &{$$self->{handler}}($queueObject->peekMessage()); }
Also doesn't work (though the print statement does print the correct value):
while($$queueObject{msmqLookupId} = $$self->{queue}->dequeue()) { &{$$self->{handler}}($queueObject->peekMessage()); print "$$queueObject{msmqLookupId}\n"; }
Does anyone have any idea what might be occurring here? The only thing I can think of is that Perl is doing something odd with the assignment of the scalar (such as assuming it isn't required and so not assigning it).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Odd scalar behaviour (Odd programmer behaviour)
by BrowserUk (Patriarch) on Mar 19, 2014 at 18:34 UTC | |
|
Re: Odd scalar behaviour
by choroba (Cardinal) on Mar 19, 2014 at 17:25 UTC | |
by SimonPratt (Friar) on Mar 20, 2014 at 08:39 UTC | |
|
Re: Odd scalar behaviour
by kennethk (Abbot) on Mar 19, 2014 at 18:12 UTC | |
by SimonPratt (Friar) on Mar 20, 2014 at 08:48 UTC |