blob: d1690ec2fa76999af6ecbd9de7c7308eb251adfd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
use strict; use warnings; use threads; use Glib; use Queue;
my $q=Glib::Thread::Queue->new(); my $q2=Glib::Thread::Queue->new(); threads->create( sub{ print "sleeping\n"; sleep 2; print "sending boo\n"; $q->enqueue('boo'); sleep 2; threads->create( sub{ print "inserting bar & foo\n"; $q->insert(0,'bar'); $q->insert(1,'foo'); print "signaling\n"; $q->signal(); print "signaling\n"; $q->signal(); }); sleep 2; print "waiting for command\n"; my $cmd=$q2->dequeue; print "got $cmd\n"; print "sending quit"; $q->enqueue('quit'); }); my $loop=Glib::MainLoop->new(); $q->add_watch(sub{ print "waking up\n"; my $foo=$q->dequeue(); print "got $foo\n"; if ($foo eq 'quit') { print "quitting\n"; $loop->quit; } elsif ($foo eq 'foo') { print "sending command\n"; $q2->enqueue('the command'); print "sent command\n"; } return Glib::SOURCE_CONTINUE; }, ); $loop->run;
|