Similar Threads:
1.how to share socket handle across threads?
Hello,
I've been rtfm'ing for days but can't a solution to this problem:
I have a thread that receives multiple client request thanks to an
endless loop through the accept() method. The new socket object
returned by accept() must be communicated to another master thread. I
am using the IO::Socket module.
When trying to use threads::shared or Thread::Queue, I keep getting
this failure:
Invalid value for shared scalar at ./X.pl line N.
So is there a way to share a socket/file handle accross threads?
Thank you
Sebastien
2.threads & threads::shared & Threads::Semaphore
Hi, All,
Hope everyone's new year is starting out very well.
I'm having to adjust a perl program I wrote to manipulate some
genetics data. Originally, the program had no memory problems but now
that I've added a couple more hashes, I'm having memory issues. It
now runs out of memory when it's about half way through processing the
data. Unfortunately, the data is very interconnected and the
statistics I need to execute involves data from several of the
hashes. I'm thinking of using threads & threads::shared in order to
be able to process, store and access the data among several of 8
processors on a Sun Spark system. Of course, I'll need to install the
threads and threads::shared modules and possible even re-compile perl
on this machine but before I go and do all this fun stuff, I wanted to
ask your opinion about whether or not I'm going down the right rabbit
hole or if I'm just digging myself a shallow grave. Would this be the
way you might do it? I've also heard of Semaphores. Might this be a
better way to go about spreading the data in hash form among several
processors on one machine and still be able to access the data in each
hash from the main program?
Thanks in advance for the excellent input I always get from this
group! :-)
Aimee Cardenas
3.Win32::Process -- Inheriting IO::Socket Handles
George Kuetemeyer < XXXX@XXXXX.COM > wrote in message
[...]
> I've created a TCP server using the IO::Socket documentation in the
> Perl IPC faq. It works like a charm, but is currently single-threaded.
> I want to try using Win32::Process to kick off a separate process for
> each connection (kind of like the Unix fork).
Heya all, same problem here... Could you help me please ? I wanna know
how to pass filehandles from perl to perl. I don't know if it is
possible...
Here is an outline of what I am doing :
1. Wait in while loop for client connection. Works fine. (same)
2. Accept a $client_handle connection handle. Works fine. (same)
3. I am waiting for tasks. The main perl creates Win32::Process
objects for each incoming task, specifying that the handles of calling
process are inherited (see below for a sample). The process runs, I/O
continues to happen in the main perl console (when using 'print'), but
I have an error when trying to send to socket. Could someone help me
please ?
[assuming that $remote is the socket (print $remote "Something\n";
works fine) and $tasknum the tasknumber =)]
Win32::Process::Create(
$ProcessObj,
"path_to\\perl.exe",
"perl.exe path_to\\test.pl $tasknum $remote",
1,
NORMAL_PRIORITY_CLASS,
".") || die "Couldn't create process!!\n";
******************************************
# test.pl
$tasknum = $ARGV[0];
$remote = $ARGV[1];
print "Hello\n";
print $remote "Hello\n";
Thanks in advance.
Sincerely yours
Dan
4.shared variables in threaded tk not being shared
Hi,
Wonder can someone help. I've been trying a few things with perl/tk and
threads with some success but cant understand a particular problem.
I've read various posts on the subject and have altered my script
accordingly but still no go! Basically the script creates some shared
variables, a sleeping thread first, then the tk window and widgets.
The thread essentially starts to update a shared variable every second
once the start button is pressed. I can see this by printing to STDOUT.
A label in the GUI points to this shared variable and is instructed to
update it.
However if i put in some debug print statements i can see that in
effect this variable is not shared as it retains the initial value only
hence the label may be updated but with the same value.
Here is the code:
use Tk;
use threads;
use threads::shared;
use strict;
my $go : shared = 0;
my $myValue : shared = 0;
my $anotherThread = threads->new(\&ticker);
sub ticker {
while (1) {
if ($go == 0) {sleep 1;}
else {
$myValue++;
print "$myValue\n";
sleep 1;
}
}
}
my $mw = MainWindow->new();
$mw->title('UDP Sniffer');
my $f1 = $mw->Frame(-borderwidth => 2, -relief => 'groove')->pack(-side
=> 'top', -fill => 'x');
my $label2 = $f1->Label(-textvariable => \$myValue, -width =>
15)->pack(-side => 'left');
$f1->Button(-text => 'Start', -command => \&start)->pack(-side =>
'left');
$f1->Button(-text => 'Stop', -command => \&stop)->pack(-side =>
'left');
$f1->Button(-text => 'Reset', -command => \&resetme)->pack(-side =>
'left');
MainLoop();
sub start {
$go = 1;
print "In the main window - $myValue\n";
##$mw->repeat(1, sub {$mw->update;});
}
sub stop {
$go = 0;
}
sub resetme {
$myValue = 0;
}
Threads are quickly becoming annoying to use as it seems they present
more problems than solutions with tk so could someone tell me what
other options i have for something similar to the above?
Thanks in advance
5.how to get filehandle-lock effective accross multi-process
Jeff Pang am Dienstag, 7. Februar 2006 10.47:
> hello,lists,
Hello Jeff
> I open a file and obtained a filehandle.then I fork a child and access this
> file in child (via the duplicate filehandle from parent).If both parent and
> child are writting to the file at the same time,the things should become
> terrible.So I should use the 'flock' call to lock the filehandle.But I find
> just in the same process,the flock is effective.In other words,when I flock
> the filehandle in child,the effect of 'flock' mean nothing to parent,and
> parent can still write to the file. the test code is shown as below:
>
> use strict;
> use warnings;
[...]
>
> when this code run,both parent and child can write to the same file,and
> maybe at the same time.
>
> How can I resolve this problem?thanks.
Seems that the flock is implemented as *advisory* lock as stated in
perldoc -f flock
.
The solution lies in the appropriate usage of flock, that means to use locking
for every access (try) to the resource. Since both accesses are within your
code, you have 100% control about that :-)
hth,
jo
6. Threads and data sharing
7. sharing semaphore with/between threads
8. share semaphore across threads