Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Test::More and semaphore handles on Windows

by blm (Hermit)
on Aug 25, 2004 at 05:44 UTC ( [id://385595]=note: print w/replies, xml ) Need Help??


in reply to Test::More and semaphore handles on Windows

I don't understand something. In

# Test to simulate semaphore growth in Test::Builder. # Grows by 4 semaphore handles per iteration. use strict; use threads; use threads::shared; my @Test_Results = (); share(@Test_Results); sub ok { my $result = {}; share($result); push(@Test_Results, $result); } my $niter = shift or die "usage: $0 number-of-iterations\n"; ok(1) for 1 .. $niter; print "Look at handle count in Windows Task Manager\n"; print "Then press [RETURN] to exit...\n";<STDIN>;

As I understand scoping, $result goes out of scope at the end of the call to ok() so why doesn't the handles get released then? Instead the handles don't seem to be released until perl.exe is finished. I guess this is to do with threads and making sure all shared data is available to all threads.

Replies are listed 'Best First'.
Re^2: Test::More and semaphore handles on Windows
by eyepopslikeamosquito (Archbishop) on Aug 25, 2004 at 06:37 UTC

    No, $result does not get destroyed then because it has been inserted into @Test_Results (which is still in scope) -- perl's reference counting keeps track of this. Running the following program with a large number of iterations, you'll see the handle count go up and up, then it drops back to the original value at the end of the program (when @Test_Results has gone out of scope).

    use strict; use threads; use threads::shared; sub test { my $niter = shift; my @Test_Results = (); share(@Test_Results); for (1 .. $niter) { my $result = {}; share($result); push(@Test_Results, $result); } } my $niter = shift or die "usage: $0 number-of-iterations\n"; test($niter); print "Look at handle count in Windows Task Manager\n"; print "Then press [RETURN] to exit...\n";<STDIN>;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://385595]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-25 19:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found