This is a segment of a much larger code line. This code segment controls the GPS device. The user clicks the "Start" button to start the device and clicks "Stop" to stop the device. The problem I am having with is when the GPS device is not responding and the user tries to close the program. When the user clicks "Start" then "Stop" and tries to close the program, the program hangs and stops responding. I can't seem to see the problem in the code and some new eyes may help.
#!/usr/bin/perl -w use strict; use Gtk2 '-init'; use Glib qw/TRUE FALSE/; use GPS::NMEA; use threads; use threads::shared; my $notebook; my $gps_entry; my $gps_start:shared = 0; my $die:shared = 0; my($ns,$lat,$ew,$lon):shared; my $gps_current; ###################################################################### +############################# #start threads my $thread_gps = threads->new( \&gps); ###################################################################### +############################# #timeouts my $timer_gps = Glib::Timeout->add(100, \&gps_position); ###################################################################### +############################# #create window my $window = Gtk2::Window->new('toplevel'); $window->signal_connect(delete_event=> sub {$die = 1; $thread_gps->joi +n; Gtk2->main_quit}); $window->set_title("GPS Test"); #create notebook $notebook = Gtk2::Notebook->new; $notebook->set_tab_pos('top'); my $gps_table = Gtk2::Table->new(3, 2, FALSE); #GPS Group (for all users) my $gps_instruction = Gtk2::Label->new(); $gps_instruction->set_markup( '<span size="small">Enter the location o +f the GPS device (i.e. "COM4" or "/dev/lao")</span>'); my $gps_label = Gtk2::Label->new( 'Location'); $gps_current = Gtk2::Label->new; $gps_entry = Gtk2::Entry->new(); $gps_entry->set_text("COM4"); my $start_stop = Gtk2::Button->new("Start"); $gps_table->attach_defaults($gps_instruction, 0, 2, 0, 1); $gps_table->attach_defaults($gps_label, 0, 1, 1, 2); $gps_table->attach_defaults($gps_entry, 1, 2, 1, 2); $gps_table->attach_defaults($start_stop, 0, 1, 2, 3); $gps_table->attach_defaults($gps_current, 1, 2, 2, 3); #start and stop GPS device $start_stop->signal_connect('clicked' => sub {if ( $start_stop->get_la +bel eq "Start") {$start_stop->set_label("Stop"); $gps_start = 1; pri +nt "$gps_start\n";} else {$start_stop->set_label("Start"); $gps_start + = 0; print "$gps_start\n";}}); $notebook->append_page($gps_table, "GPS"); #add widgets $window->add($notebook); $window->show_all; Gtk2->main; ###################################################################### +############################## #GPS Thread sub gps{ while (1) { #If program ends stop the loop goto END if $die == 1; if ($gps_start == 1) { #start the GPS Device my $gps_device = GPS::NMEA->new(Port => 'COM4', Baud => 4800); print "$gps_device\n"; #start the loop for (;;) { #stops the warnings in the GPS device module local $^W = 0; ($ns,$lat,$ew,$lon) = $gps_device->get_position; print "$gps_device\n"; goto END if $die == 1; last if $gps_start == 0; sleep 3; } print "$gps_device\n"; #undef $gps_device; } else {sleep 4} } END: } ###################################################################### +############################## #GPS position timeout sub gps_position{ #set the current GPS position $gps_current->set_label("$ns $lat, $ew $lon") if $gps_start == 1 and + defined($ns); $gps_current->set_label("N/A") if $gps_start == 0; return 1; }

In reply to GPS Widget by deadpickle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.