in reply to Perl/Tk Multithreading

Hi, you don't give a complete code script that we can actually run and test, so it's hard to say what is happening. The line in your thread
$FunctionsToLaunchThread{$FunctionName}->@ArgumentsThread);
isn't clear. What do you expect that to do?

Also, you may have seen that while(1) thread code construct, from early examples of running threads from Tk, but now with later versions of Threads you can use signals to kill threads. See using the thread->kill() feature on linux

Finally, since you are using some network code, you may be getting blocking on i/o, see Threads, bash, and networking

It would be useful for you to create as simple of a running script as possible, which demonstrates your problem.


I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re^2: Perl/Tk Multithreading
by mahis_431 (Novice) on Jul 17, 2011 at 14:46 UTC
    sorry I missed the opening parentheses for @Arguments first I declared a hash where functions are stored which I call them in thread, like: %FunctionsToLaunchThread = ( "run_script" => \&run_script ); and then I created a thread: $Thread = threads->create( \&WorkThread ); Now I created a subroutine sub runtk where i assigned
    $FunctionName = "run_script"; @ArgumentsThread = ($new);
    so now the following $FunctionsToLaunchThread{$FunctionName}->(@ArgumentsThread); becomes $FunctionsToLaunchThread{run_script}->($new) which is \&run_script->($new); The above function is expected to call the function in the thread. The run_script subroutine I already shared in previous post. As you said its true I am facing a blocking problem on the device I/O. The thread is created and is loading the do "add.pl" but now in the add.pl I am using network modules, this modules are blocked for the thread to work completely. I am getting following errors: 1. "unable call method purge_all() in the Modem.pm on undentified variable" 2. "undefined value for a shared variable at line.... in Modem.pm" So is there any way to work around this. I wanted to share the working code but it is too big.
      I am getting following errors: 1. "unable call method purge_all() in the Modem.pm on undentified variable" 2. "undefined value for a shared variable at line.... in Modem.pm" So is there any way to work around this.

      You probably should work on getting the network code functioning on it's own, before putting it into a thread. Some tricks are to wrap the network code in an eval with an alarm. See Thread Safe alarms?.

      You are not showing a complete code for this, so as a guess, one of the other mistakes may be that you are declaring your GSM network module globally in the main thread.... try to confine all network code, including the use statement, to the worker thread. Many modules are still not thread safe.


      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku ................... flash japh
Re^2: Perl/Tk Multithreading
by mahis_431 (Novice) on Jul 17, 2011 at 15:09 UTC
    I will see if i can post a simple working code....actually the real working code is very big and other external files are loaded in mainscript. This external files are using network modules. This is the point where i am getting troubles.