gtk2 和线程中的分段错误

segmentation fault in gtk2 and thread

我遇到了这个问题,这个小示例代码将检查用户名是否存在于 MySQL 服务器上。

#!/usr/bin/perl
use Gtk2 '-init';
use Glib qw/TRUE FALSE/;
use threads;
use threads::shared;
use DBI;
use DBD::mysql;

our $type="mysql";
our $database="store";
our $host="localhost";
our $port="3306";
our $tablename="topic";
our $user="root";
our $pwd="killme32";

our $dsn="dbi:$type:$database:$host:$port";
our $query;
our $queryhandle;
my $str:shared=0;

my $window=Gtk2::Window->new;
$window->signal_connect('delete_event',sub{Gtk2->main_quit;});
$window->set_title("Perl Gtk2 Tutorial");

my $vbox=Gtk2::VBox->new;
my $label=Gtk2::Label->new("Username: ");
my $button=Gtk2::Button->new("Login");
my $entry=Gtk2::Entry->new();
$button->signal_connect(clicked=>sub{
    $str=$entry->get_text;
    my $thr=threads->create(\&continue_checking);
});
$vbox->add($label);
$vbox->add($entry);
$vbox->add($button);
$window->add($vbox);
$window->show_all;
Gtk2->main;
sub continue_checking{
    our $connect=DBI->connect($dsn,$user,$pwd)or die &mysql_Err;
    $query="SELECT username FROM login WHERE username=\"$str\"";
    $queryhandle=$connect->prepare($query);
    $queryhandle->execute;
    $queryhandle->bind_columns(undef, \my $user_name);
    while ($queryhandle->fetch()) {
        if("$str" eq "$user_name"){
            &main;
        }
    }   
}
sub main{
    my $mw=Gtk2::Window->new;
    $mw->set_default_size(250, 250);
    my $label=Gtk2::Label->new("username $str is already exist");
    $mw->add($label);
    $mw->show_all;
    $mw->show;
}

ERROR Result: GLib-GObject-WARNING **: cannot register existing type `GConnectFlags' at /usr/lib/perl/5.14/DynaLoader.pm line 207. Pango-WARNING **: shaping failure, expect ugly output. shape-engine='BasicEngineFc', font='DejaVu Sans 9.9990234375', text='' at server.pl line 40. Segmentation fault

尝试添加

use Gtk2 qw/-init -threads-init/;
Glib::Object->set_threadsafe (1);