Wow. Thanks a lot, i learned a good bit about threads from this and have managed to launch the thread in a manner that eradicates the error message and probably makes the thread a lot happier by not encumbering it with the OpenGL stuff unnecessarily:
use threads;
use threads::shared;
use Carp;
use Config::Simple;
use Win32::OLE('in');
my $memory_use;
my %c;
BEGIN {
share($memory_use);
tie %c, 'Config::Simple', 'lifevis.cfg';
sub update_memory_use {
my @state_array;
my $pid = $PROCESS_ID;
my $sleep_time = ( $c{sync_delay} * $c{full_update_offset} ) /
+ 1000;
my $WMI_service_object = Win32::OLE->GetObject("winmgmts:\\\\.
+\\root\\CIMV2")
or croak "WMI connection failed.\n";
while (1) {
@state_array = in $WMI_service_object->ExecQuery(
'SELECT PrivatePageCount FROM Win32_Process'
. " WHERE ProcessId = $pid",
'WQL',
0x10 | 0x20
);
$memory_use = $state_array[0]->{PrivatePageCount};
sleep $sleep_time;
}
return 1;
}
my $thr = threads->create( \&update_memory_use );
$thr->detach();
}
use OpenGL qw/ :all /;
I wasn't planning to actually use OpenGL threaded anyhow, but actually only wanted to offload blocking operations that can work in the background.
One thing i stumbled across though: Do you think it would be possible to safely create a thread that binds the glut keyboard input callbacks and then creates a second opengl main loop that processes ONLY those? Alternatively, is there a way to do event systems directly within perl or while loops that can react quickly, but don't use up 100% CPU?
In a similar vein: If i would, say, declare $sleep_time above outside the thread, then modify it in the main program, would the changes be noticed by the thread or would it need to be shared first?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.