Hello Plymouth, Wednesday, April 13, 2005, 7:26:43 AM, You wrote:
PR> My script uses threads module for creation several threads. Each thread prints PR> certain letter for several times via some pause. Kind of letter, number of times, PR> length of pause are different for every thread. These threads should be work in PR> parallel. Also, I have to synchronize all starts of the threads, that is all 9 PR> children should be start at the same time, almost 'simultaneously' (at least for PR> eyes) , without visual delays between each other. Still I've too large total PR> delay between 'a'-letter and 'i'-letter: about 9 secs on Pentium 133. I've tried: PR> Thread::Barrier - thread execution barrier/ PR> Win32::IPC - Base class for Win32 synchronization objects/ PR> Proc-SyncExec-1.01 (non-downloadable from CPAN with 'ppm install'), PR> but nothing could affect to the starts synchronization. Also I'd trying to use PR> locks, semaphores, alarms, cond_wait, cond_signal, cond_broadcast... without a PR> success. Maybe, Thread::Signal?.. IPC's kill()?.. PR> This script is CGI, for win32, IE6; it uses buffering $|++, which may sometimes PR> be a cause of certain visual problems in browser. Anyway, you can run it just in PR> a shell and look at process of printing. It's most likely, just after start and PR> HTML-dumping you won't see: abcdefghi (etc in non-regulated order). It will be PR> something like this: ababcbacd (etc in non-regulated order). As I understand, PR> such the asynchronous starts do happen due to sequential subN's works out PR> without waiting of preparing all future threads to run, every time once each PR> subN being called in the code: my $thrN = threads->>new(\&subN); PR> So, how to sync all the threads starts (or just all letters printing's start)? As far as I understand You need that FIRST NINE LETTERS were all different. Later its order may be pretty arbitrary and depends of delays etc. If my suggestion is correct, then after running code below about 50 times each time i get needed result use strict; $|++; use warnings; use Time::HiRes; use threads; use threads::shared; my $count : shared; sub sub1 { $count -= 1; my $cur_var = 0; for($cur_var = $cur_var; $cur_var <= 8; $cur_var++) { redo if $count; print "<script>set('cell1$cur_var', 'a')</script>\n"; Time::HiRes::sleep(0.4); } } sub sub2 { $count -= 1; my $cur_var = 0; for($cur_var = $cur_var; $cur_var <= 5; $cur_var++) { redo if $count; print "<script>set('cell2$cur_var', 'b')</script>\n"; Time::HiRes::sleep(0.2); } } sub sub3 { $count -= 1; my $cur_var = 0; for($cur_var = $cur_var; $cur_var <= 11; $cur_var++) { redo if $count; print "<script>set('cell3$cur_var', 'c')</script>\n"; Time::HiRes::sleep(0.3); } } sub sub4 { $count -= 1; my $cur_var = 0; for($cur_var = $cur_var; $cur_var <= 6; $cur_var++) { redo if $count; print "<script>set('cell4$cur_var', 'd')</script>\n"; Time::HiRes::sleep(1.1); } } sub sub5 { $count -= 1; my $cur_var = 0; for($cur_var = $cur_var; $cur_var <= 2; $cur_var++) { redo if $count; print "<script>set('cell5$cur_var', 'e')</script>\n"; Time::HiRes::sleep(0.5); } } sub sub6 { $count -= 1; my $cur_var = 0; for($cur_var = $cur_var; $cur_var <= 9; $cur_var++) { redo if $count; print "<script>set('cell6$cur_var', 'f')</script>\n"; Time::HiRes::sleep(0.6); } } sub sub7 { $count -= 1; my $cur_var = 0; for($cur_var = $cur_var; $cur_var <= 3; $cur_var++) { redo if $count; print "<script>set('cell7$cur_var', 'g')</script>\n"; Time::HiRes::sleep(0.7); } } sub sub8 { $count -= 1; my $cur_var = 0; for($cur_var = $cur_var; $cur_var <= 5; $cur_var++) { redo if $count; print "<script>set('cell8$cur_var', 'h')</script>\n"; Time::HiRes::sleep(0.8); } } sub sub9 { $count -= 1; my $cur_var = 0; for($cur_var = $cur_var; $cur_var <= 6; $cur_var++) { redo if $count; print "<script>set('cell9$cur_var', 'i')</script>\n"; Time::HiRes::sleep(0.9); } } $count = 9; my $thr1 = threads->new(\&sub1); my $thr2 = threads->new(\&sub2); my $thr3 = threads->new(\&sub3); my $thr4 = threads->new(\&sub4); my $thr5 = threads->new(\&sub5); my $thr6 = threads->new(\&sub6); my $thr7 = threads->new(\&sub7); my $thr8 = threads->new(\&sub8); my $thr9 = threads->new(\&sub9); $thr1->join; $thr2->join; $thr3->join; $thr4->join; $thr5->join; $thr6->join; $thr7->join; $thr8->join; $thr9->join; -- Best regards, Sergey mailto:[EMAIL PROTECTED] _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs