The CPAN documentation on perl threads state the overhead of creating
a thread is rather large. Anyone know why or could point me to a
website that explains the reason.
TIA,
ves
Well, I warned you all the bullshit would come out, and it did.
Unix didn't have threads until Microsoft did, er showed them how.
So it seems windows is the natural api threading model.
The bullshit you read from the previous posters has to do with alot
of things. One is they don't know what a real os native,
kernel mode threading model is. Otherwise, they wouldn't be so
arogant as to push off what I said, which is the root of a
threading model.
That model is to save the state of the current thread of
execution, then switch to a different state. There is NO
making a duplicate copy of CODE for each thread. That
includes the Perl interpreter (forking, or spawning
a new process is different as it has a seperate "address
space". You know what that is don't you?)
Since there is no duplication of code in a new thread of
execution, theres only auto data, stack data and registers
that include segment pointers like SP, IP, to save state for.
Globals are inherintly shared in the native model and must
be specifically locked for exclusive access.
Note the difference between a new process and a new thread.
That being threads share the same address space, processes
do not. Threading means global (shared) data can be accessed by
any running thread in the process when its got focus
(aka: a time-slice).
But how does a interpreted language do threading?
Datawise, if its possible that language global
data within a thread (and we're talking threaded code
that are subroutines in Perl) can be modified within
a subroutine without data locks, then the only way the
interpreter can survive without forcing subroutines
to lock that data, is to create duplicate set of data
(auto-variables) for each thread. Remember, your Perl
subroutine is not the thread. The thread envelope has
to be enlarged so that your subroutine is the currently
running code that was called by the interpreter (all threads
of execution are called by a single copy of the interpreter)
with a different set of auto data. Auto data is that which is
declared within the block (I believe its lexical in Perleaz).
Given that, what seperate data is needed for each thread
in Perl. Well clearly, if Perl calls your code in a single
thread, all the data of the caller (interpreter) has to be
"auto-data" of the scope of the interpreter. Otherwise for
those to be considered global would need a lock for almost
every module in perl since they access main variables all
the time. The overhead now is on "auto data". Each
new thread creates a new copy of the interpreters auto data.
The scope of the currently running code has expanded to
now be the block of the interpreter, not of the single
subroutine.
Therein lies the absolute bullshit !!!