"be consistent" | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I've been doing that way in all my thread examples. :-) What I do is first setup the shared variables, then IMMEDIATELY creating the threads and put them in a sleep loop, waiting for
a signal(thru shared vars) to wake up and start running. I usually use a 1 second loop in the threads, which may seem sluggish, but you could reduce it to milliseconds if desired.
Even in the latest Gtk2 code, which allows some fancier thread work, thru their thread-safety mechanism, experts like muppet still say the best way is to do it like you suggest. Create the threads first, before anything else is declared, and you will have few problems. This is the basic thread I use, you can either hard code the threads code, or pass it via shared-variable and eval it. When the thread is created, it goes right to sleep, and wakes up once per second to see if it needs to awake. The one drawback with this method, is you need to clean them up when exiting......wake them up, and tell them to die, then join them.
I'm not really a human, but I play one on earth. flash japh In reply to Re: threads: spawn early to avoid the crush.
by zentara
|
|