0

I just played around with the Win32-GUI in combination with threads (Perl 5.16) and I came up with some warnings and errors I do not really understand.

Code is the following:

    use strict;
    use warnings;
    use Win32::GUI();
    use threads;

    my $main = Win32::GUI::Window->new(
        -name => 'main',
        -title => 'Multithreaded Test',
        -size => [300,100],
    );
    my $button1 = $main->AddButton(
        -name => 'button1',
        -text => 'Click me',
        -pos => [10,10],
        -width => 120,
    );
    sub button1_Click {
        my $thread1 = threads->create(\&do_something);
        $thread1->join();
    }
    sub do_something {
        sleep(1);
    }
    $main->Center();
    $main->Show();
    Win32::GUI::Dialog();

When I click on the button and the thread is joined after 1 second, I get this console output:

Free to wrong pool 35bcd90 not 2a1718 at C:/Perl/site/lib/Win32/GUI.pm line 3480 during global destruction. Free to wrong pool 35bcd90 not 2a1718 at C:/Perl/site/lib/Win32/GUI.pm line 3480 during global destruction. Scalars leaked: 1

I found several topics about this "Scalars leaked" problem, but sadly not a solution that is working.

Do you have any idea?

Thanks,

Max.

  • Interesting, I just pasted your code and force installed Win32::GUI. I don't get those errors. I'm Perl v5.16.2 on Windows XP. – Craig Treptow Jan 16 '13 at 21:12
  • 1
    You can't do this. `Win32::GUI` isn't thread-safe. There may be a work-aruond for what you want to do: I suggest you google for `Win32::GUI threads` – Borodin Jan 16 '13 at 21:12
  • Okay thank you. What would be the alternative in a scenario like this? I want to do something in the background when I click on a button, but the GUI should be controllable in the meantime. Would it be better to use WxWidgets? – user1666356 Jan 17 '13 at 14:44

1 Answers1

0

This may not be the problem, but you need to provide a Terminate handler for your main window that stops the main message loop. Like this

sub main_Terminate { -1 }
Borodin
  • 126,100
  • 9
  • 70
  • 144