create thread from within another?

G

gargoyle

I'm using ActivePerl 5.8.6.811 and have a question regarding threads.

What are the implications of starting a thread from within another (as
opposed to starting all threads from the main thread, ie. tid 0)? Will
any nasty bugs or strange issues come to bite me? In other words, was
the ithreads model written to handle this sort of behavior?

The reason I'm asking is because I'm trying to find a way to keep memory
footprint to a minimum, and yet be able to spawn new threads at any
given time. I figured a "dispatcher" thread could be started as early
as possible (before most modules are loaded, data structures filled,
etc.) and then when a new worker thread is needed, main could signal the
dispatcher (via a queue) and tell it to create a new thread with some
specific parameters (based on the job that needs to be accomplished at
that given moment).

Will this work, or is it just some crazy fantasy?
 
A

Anno Siegel

gargoyle said:
I'm using ActivePerl 5.8.6.811 and have a question regarding threads.

What are the implications of starting a thread from within another (as
opposed to starting all threads from the main thread, ie. tid 0)? Will
any nasty bugs or strange issues come to bite me? In other words, was
the ithreads model written to handle this sort of behavior?

The reason I'm asking is because I'm trying to find a way to keep memory
footprint to a minimum, and yet be able to spawn new threads at any
given time. I figured a "dispatcher" thread could be started as early
as possible (before most modules are loaded, data structures filled,
etc.) and then when a new worker thread is needed, main could signal the
dispatcher (via a queue) and tell it to create a new thread with some
specific parameters (based on the job that needs to be accomplished at
that given moment).

What makes you think you can conserve memory that way?

Unlike a child process, a thread handles concurrency in the address
space of one process. It doesn't duplicate everything you have loaded
at the point of dispatch.

Anno
 
K

kongyew

Hi,

I thought cost of thread creation is smaller than process.

(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,779
Messages
2,569,606
Members
45,239
Latest member
Alex Young

Latest Threads

Top