Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Threads - "Attempt to free non-existent shared string"

Status
Not open for further replies.

MoshiachNow

IS-IT--Management
Feb 6, 2002
1,851
IL
HI,

Just beginning with threads...
Code:

$thr = threads->create({'context' => 'void'},\&THREAD,$computer);
sub THREAD {
$computer=shift;
print "COMPUTER=$computer\n";
$objWMIService = Win32::OLE->GetObject("winmgmts:\\\\$computer\\root\\CIMV2") or &disp("WMI connection failed.\n",'RED');
$colItems = $objWMIService->ExecQuery("SELECT * FROM Win32_Product", "WQL",
wbemFlagReturnImmediately | wbemFlagForwardOnly);
}
$thr->join();

=============================================
result:

"Attempt to free non-existent shared string 'ExecQuery', Perl interpreter: 0x235d27c at D:\
DOcuments\Ripro\AIX\myscripts\pod_check.pl line 988.
Free to wrong pool 218fd28 not 222770 at D:\DOcuments\Ripro\AIX\myscripts\pod_check.pl lin
e 988."

The thing is that 'ExecQuery' WAS working well till put in thread...Appreciate ideas.
Thanks


Long live king Moshiach !
 
strawclutch1:
check the environment, you may need to run some process to restore environment variables in the thread, or avoid using environment variables in the thread altogether.

strawclutch2:
you'll need to create an environment for each thread, as it doesn't seem to want to share resources. Should there be a 'new' instance of the object created?
Code:
$objWMIService = [COLOR=red]new[/color] Win32::OLE->GetObject("winmgmts:\\\\$computer\\root\\CIMV2") or &disp("WMI connection failed.\n",'RED');

Hope one of those puts you on the right track

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Thanks.

1.Tried changing to :
sub THREAD {
use Win32::OLE qw( in );
my $computer=shift;
print "COMPUTER=$computer\n";
$objWMIService = Win32::OLE->GetObject("winmgmts:\\\\$computer\\root\\CIMV2") or &disp("WMI connection failed.\n",'RED');
$colItems = $objWMIService->ExecQuery("SELECT * FROM Win32_Product", "WQL",
wbemFlagReturnImmediately | wbemFlagForwardOnly);
}

This did not help.any specific enviromental variables I have to change ?

2.
$objWMIService = new Win32::OLE->GetObject("winmgmts:\\\\$computer\\root\\CIMV2") or &disp("WMI connection failed.\n",'RED');

Produced:

Usage: Win32::OLE->new(PROGID[,DESTROY]) at D:\DOcuments\Ripro\AIX\myscripts\pod_check.p
line 975.
Thread failed to start: Can't call method "GetObject" on an undefined value at D:\DOcume
s\Ripro\AIX\myscripts\pod_check.pl line 975.
Attempt to free non-existent shared string 'ExecQuery', Perl interpreter: 0x242d294 duri
global destruction.
Free to wrong pool 24de1e8 not 222770 during global destruction.





Long live king Moshiach !
 
Actualy,

$objWMIService = Win32::OLE->GetObject("winmgmts:\\\\$computer\\root\\CIMV2") || &disp("WMI connection failed.\n",'RED');

Returns error "WMI connection failed".
So the issue is that this line fails,thus failing the rest.
Why this line works WITHOUT a thread,and does not with ?
What enviromental variables should I change ?
Thanks


Long live king Moshiach !
 
whatever you're setting up above the fork to a new thread may need to be incorporated into the thread setup in order to carry out the task.

I'm only clutching at straws, be warned ;-)

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Thanks,

I think my problem is now that my version of ActiveState does NOT support multi-threading.
So I'm now bracking my head on how to make it to support.
Thanks

Long live king Moshiach !
 
The error now is :

Thread failed to start: Can't call method "ExecQuery" without a package or object reference at D:\DOcuments\Ripro\AIX\myscripts\pod_check.pl line 981.
Free to wrong pool 221e868 not 222770 during global destruction.

The code is:

$thr = threads->new(\&THREAD,"$computer");
sub THREAD {
use Win32::OLE qw( in with );
my $computer=shift;
&disp("COMPUTER=$computer\n");
use constant wbemFlagReturnImmediately => 0x10;
use constant wbemFlagForwardOnly => 0x20;
my $objWMIService = Win32::OLE->GetObject("winmgmts:\\\\$computer\\root\\CIMV2") || &disp("WMI connection failed.\n",'RED');
my $colItems = $objWMIService->ExecQuery("SELECT * FROM Win32_Product", "WQL",
wbemFlagReturnImmediately | wbemFlagForwardOnly);
}
$thr->join();


Long live king Moshiach !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top