A personal plee, ignore at will. Please insert some horizontal whitespace (and use proper indentation, though I realise that that can get screwed through posting/cutting/pasting).

sub check_1 { my $query = " SELECT * FROM __InstanceCreationEvent WHERE TargetInstance ISA'Win32_NTLogEvent' "; my $wbemloc = new Win32::OLE( "WbemScripting.SWbemLocator" ); $wbemloc->{ Security_ }{ Privileges } ->AddAsString( "SeSecurityPrivilege" ); my $wbemsvc = $wbemloc->ConnectServer( ".", "root/cimv2" ); $wbemsvc->{ Security_ }{ ImpersonationLevel } = 3; my $wbemevtsrc = $wbemsvc->ExecNotificationQuery( $query ); while( 1 ) { my $wbemobj = $wbemevtsrc->NextEvent(); my $msg = $wbemobj->{ TargetInstance }{ Message }; $msg =~ s/\t//g; my @array = split( /\r\n/, $msg ); my $tst = join( ';', @array ); $tst =~ s/;;/;/g; print $tst."\n"; } }

More readable than above? I had to resort to sorting the source to determine that check_1 and check_2 were identical.

Which brings me to my second point. Cut&paste code is bad (bad,bad;), and completely unnecessary. The whole point of subroutines is that you can call them twice or more. (Caveat: closures can complicate this!)

This works fine.

#! perl -slw use strict; use threads qw[ async ]; sub sub1 { my $no = shift; while(1) { print "in sub $no"; select undef, undef, undef, 0.1; } } async \&sub1, 1; ## Param = '1' sub1( 2 ); ## Param = '2' __END__ P:\test>397011 in sub 2 in sub 1 in sub 2 in sub 1 in sub 2 in sub 1 Terminating on signal SIGINT(2)

And that brings up the third point which is speculative because I don't have the "WbemScripting.SWbemLocator" (as far as I am aware) in order to verify this.

Many OLE .dll's use what I believe is called the 'apartment' model. The in's and out's of this are complicated, off-topic for this place, and I'm not sure I remember them correctly (if I ever did). Breifly, there are various ways of building DLLs, some of which allow that DLL to be called from as many processes, and as many threads within those processes as you like. Ie. they are fully reentrant. Others can only be entered once from within a given process. There are other variations as well--see MSDN for more/better/accurate information.

The upshot is that it may be that the DLL that provides the OLE object you are calling is not compatible with threading. It would be a good thing to know, before continuing to try do what your doing, if this is the case or not. The best I can suggest is that you consult the docs, or vendor, before expending more energy trying to solve this.

Alternatively, if you have and know VB, then try doing what your doing from (minimally) from there. If you hang up there too, then you probably have your answer.

Of course, it may be that your real code doesn't try to access the same identical object/event loop concurrently, and this is just more sample code.

Ultimately, sample code rarely helps solve real problems.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

In reply to Re^2: multiple infinitive loops by BrowserUk
in thread multiple infinitive loops by ozkaa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.