Managing multiple threads with `local variables`

BlitzMax Forums/BlitzMax Programming/Managing multiple threads with `local variables`

TomToad: Are those methods already available as part of the threading module, or are those o/s API calls? (I've heard that `real` thread-local-storage API's are relatively slow compared to a manually coded technique?)

I should have clarified about local variables. Yes locals will be temporary variables confined to the thread, but that's not what I'm asking. I need to use globals.

The problem is, the thread is going to be calling a number of functions and some of the functions are going to modify data that affects which functions the thread is going to call in future. So decisions made within the functions affect which functions get called from the higher level.

For efficiency, this requires that the data determining which functions get called be stored in Global variables (and because a function can't really modify a local variable outside the scope of the function - and passing return values is not efficient enough or flexible enough). The globals are therefore accessible to all threads, but each thread needs its *own set* of Globals. The threads won't share the globals - the data isn't global for enabling threads to share them, they're global to enable the functions to modify and interact with the thread's workload.

In other words, the thread modifies and allocates its own workload via the very functions it calls which are a part of its workload. It's a circular thing and I need globals to make it work, just not the same globals for each thread. You could call it a `self managing thread pool`.

I don't really need the variables to be static, the threads will be forming a thread pool and if the time comes for a thread to be deleted it's okay to lose its global data.

My system is working for one thread (ie not using threads) but I need it to be fully scalable to a large number of threads in a pool. I figured if I just simply put all my globals into another level of array dimensions, and somehow associate an index in the arrays with each thread, then I can get each thread to modify a unique set of global data. But I don't see how I can do that because somehow the thread needs to be associated with an index number which has to be stored somewhere in such a way that the thread's workload functions can know what array elements to modify. So how can I do that?