[fpc-devel] THREAD Programming IN FPC

Micha Nelissen micha at neli.hopto.org
Tue Jan 9 08:27:38 CET 2007


Jason P Sage wrote:
> The routines I CALL USUALLY have a few variables they use to keep track of
> counters or stuff that is only VALID during the life of the Call. 
> 
> My Problem is sometimes THESE Variables that are local to the sub routines
> are getting stomped in longer routines (That perhaps are getting task
> switched).

First, why the random capitalization ?

Do you have a test program that reproduces this issue ?

> The Question is the local variable "i" safe all the time? Does it get its
> own stack space? Or does it get stomped by multiple threads because its only
> allocated in memory one time but multiple threads are calling the routine
> "My Routine"

> My experience has led me to the impression that local variables are
> allocated on the stack. If they are, does each thread own its own stack
> space? Do local variables get allocated on the THREAD's Stack? Or the main
> program's?

It gets allocated on the stack, and every thread has its own stack.

> Are AnsiStrings managed intelligently in threaded applications? Meaning - do
> they have the same rules as other variables concerning multi-threaded
> applications or does the memory counters or "reference counts" to chunk of
> mem get hosed?

They are not thread-safe AFAIK. It's hard to pass them safely between 
threads, though not impossible, however you have to know exactly how 
things work.

Micha



More information about the fpc-devel mailing list