DELTA 404 8466 209
SVN  dŽ<Ž<€Ž<package thread_example_1;
use threads;
use Thread::Semaphore;

my $semaphore = new Thread::Semaphore(0);

sub onStart
{
    if(eval{\&owl::queue_message}) {
        threads->new(\&threadLoop)->detach();
        owl::new_command(reply_worker => \&reply_worker);
    } else {
        # Our owl doesn't support queue_message. Unfortunately, this
        # means it probably *also* doesn't support owl::error. So just
        # give up silently.
    }
}
push @::onStartSubs, \&onStart;


sub onMainLoop
{
     $semaphore->up();
     threads->yield();
     $semaphore->down();
}
push @::onMainLoop, \&onMainLoop;


sub threadLoop()
{
    my $i = 0;
    my $now = time();
    my $next = $now + 3;
    
    while (1)
    {
	$semaphore->down();
	$now = time();
	$timestr = localtime($now);
	if ($::shutdown)
	{
	    my $m = owl::Message->new('type' => 'generic', 
				      'direction' => 'in',
				      'body' => "Thread terminated - $now",
				      'sender' => 'worker thread',
				      'recipient' => 'owl client');
	    
	    owl::queue_message($m);
	    
	    $semaphore->up();	    
	    return;
	}

	if ($now > $next)
	{
	    $next = $now + 3;
	    my $m = owl::Message->new('type' => 'generic', 
				      'direction' => 'in',
				      'body' => "$now",
				      'sender' => 'worker thread',
				      'recipient' => 'owl client',
                                      'replycmd' => 'reply_worker');
	    owl::queue_message($m);
	}
	$semaphore->up();
    }
}

sub reply_worker {
    owl::start_edit_win("perlwrite worker thread", \&process_reply);
}

sub process_reply {
    my $reply = shift;

    my $msg = owl::Message->new(
        type   => 'generic',
        direction => 'out',
        body => $reply,
        sender => 'owl client',
        recipient => 'worker thread',
        replycmd => 'reply_worker');
    owl::queue_message($msg);
}
ENDREP
id: 46.0.r418/1893
type: file
pred: 46.0.r414/542
count: 4
text: 418 0 1867 1852 7579fb6fe6a535e57d798bf414e4aaa3
cpath: /trunk/conf.asedeno/owl/modules/thread_example_1.pl
copyroot: 0 /

PLAIN
K 13
ColorUtils.pl
V 20
file 43.0.r404/17051
K 11
PageView.pl
V 20
file 44.0.r404/16887
K 13
VT-asedeno.pl
V 18
file 45.0.r414/361
K 19
thread_example_1.pl
V 19
file 46.0.r418/1893
END
ENDREP
id: 42.0.r418/2279
type: dir
pred: 42.0.r414/927
count: 4
text: 418 2081 185 185 d9cfa181455d375671327a9cd54dc934
cpath: /trunk/conf.asedeno/owl/modules
copyroot: 0 /

PLAIN
K 7
modules
V 18
dir 42.0.r418/2279
K 10
owlconf.pl
V 18
file 47.0.r412/973
END
ENDREP
id: 41.0.r418/2540
type: dir
pred: 41.0.r414/1186
count: 4
text: 418 2447 80 80 6a01dab7a2571841bfe742b5aa6b9c2d
cpath: /trunk/conf.asedeno/owl
copyroot: 0 /

PLAIN
K 6
README
V 20
file 40.0.r404/18118
K 3
owl
V 18
dir 41.0.r418/2540
K 7
owlconf
V 20
file 48.0.r404/17974
END
ENDREP
id: 3z.0.r418/2823
type: dir
pred: 3z.0.r414/1469
count: 4
text: 418 2699 111 111 a96f2e16a00c29cd72b68fb23d38d92d
cpath: /trunk/conf.asedeno
copyroot: 0 /

PLAIN
K 7
CVSROOT
V 16
dir 4.0.r112/895
K 12
conf.asedeno
V 18
dir 3z.0.r418/2823
K 3
owl
V 17
dir g.0.r417/3386
END
ENDREP
id: 1.0.r418/3104
type: dir
pred: 1.0.r417/3659
count: 406
text: 418 2980 111 111 6a976d22f83992d3d9d81bf9a9bd72b1
cpath: /trunk
copyroot: 0 /

PLAIN
K 8
branches
V 17
dir 2.0.r317/7068
K 4
tags
V 16
dir 3.0.r391/435
K 5
trunk
V 17
dir 1.0.r418/3104
END
ENDREP
id: 0.0.r418/3365
type: dir
pred: 0.0.r417/3920
count: 418
text: 418 3248 104 104 7fd443d865b73116aaad6e88eba1e706
cpath: /
copyroot: 0 /

46.0.t417-1 modify true false /trunk/conf.asedeno/owl/modules/thread_example_1.pl


3365 3504
