The short program below is a test stub that I've written to re-create an issue I'm having with an ActiveX control I'm developing with ActiveState Perl 5.8 and the Perl Dev Kit (both beta).
When compiled, the stub runs fine until I exit the 3rd-party app that called CreateObject() on my DLL. At that point Dr.Watson pops and the application crashes.
Debugging an ActiveX control is proving to be a bit difficult and is the reason why I redirect stdout/err to a file at the beggining of my test stub.
This is the basic "life" of my DLL:
1) VB app calls CreateObject() on my DLL
2) VB app calls InitIO()
This is where I spawn a thread that just sits in a while() loop and detach it.
3) When the VB app is closed it calls ShutdownIO()
This is where I set the shared variable $running to '0' so that the child will exit it's while() loop and allow the thread to close.
These are the log results with the code as is below:
ShutdownIO()
A thread exited while 2 other threads were still running.
You'll notice that the DLL object is destroyed before the child thread has a chance to exit the while() loop. The 'print "Exiting...\n";' never gets evaluated and it displays an message about other threads exisiting.
If I uncomment the sleep() call in ShutdownIO() then the debug shows that the child thread exits it's while() loop...
ShutdownIO()...
Exiting...
Free to wrong pool 1283b00 not 849b58 during global destruction.
But then the "Free to wrong pool..." messages appear.
Does anyone see something painfully obvious that I'm doing wrong?
-Nitrox
use threads;
use threads::shared;
use strict;
use warnings;
use Win32;
open(STDOUT, ">>cp_std.log") || die "Can't redirect stdout";
open(STDERR, ">&STDOUT") || die "Can't dup stdout";
select(STDERR); $| = 1;
select(STDOUT); $| = 1;
my $running = 0;
share($running);
exit;
sub main_loop {
while($running){
Win32::Sleep(250);
}
print "Exiting...\n";
}
sub ShutdownIO {
print "ShutdownIO()...\n";
$running = 0;
#Win32::Sleep(2000);
return;
}
sub InitIO {
if(!$running){
$running = 1;
my $poll_thrd = threads->create("main_loop","");
$poll_thrd->detach;
}
return("");
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.