#!/usr/bin/perl use strict; use Tk; use threads; use Thread::Queue; my $RequestQ = Thread::Queue->new; my $worker = threads->new( \&worker ); my $top = MainWindow->new(); my $menubar = $top->Menu( -type => 'menubar' ); $top->configure( -menu => $menubar ); my $filemenu = $menubar->cascade( -label => '~File', -tearoff => 0 ); $filemenu->command( -label => '~Run xterm', -command => [ \&run_it ], ); $filemenu->command( -label => 'E~xit', -command => [ \&Shutdown ], ); print STDERR "there's a tiny window open, it's small but it's there\n"; MainLoop(); print STDERR "Exit Main loop \n"; ############################ sub Shutdown { $RequestQ->enqueue(undef); # quit the worker $worker->join; print STDERR "FINISHED Shutdown\n"; exit; # Clean up Tk } ############################ sub run_it { my $cmd = system "xterm -e bash &"; print STDERR "running $cmd\n"; $RequestQ->enqueue($cmd); } ################## sub worker { while ( my $target = $RequestQ->dequeue ) { print STDERR "Request $target Read\n"; system $target; print STDERR "Finished target\n"; } print STDERR "Thread exit\n"; }