Closed AXKuhta closed 3 years ago
Added ThreadedGlobal
variable scope, which implements thread local storage. e.g.
ThreadedGlobal counter:Int
' ...
Function ThreadFunc:Object(obj:Object)
counter = 0
For Local i:Int = 0 until 100
counter :+ 1
Next
End Function
GCC features a
__thread
variable specifier that will make the variable unique to the current thread. I've managed to harness it's power by using an external .c file that declares the variable along with set/get functions andExtern
ing the set/get functions from BlitzMax.Here's the relevant code in my small web server: https://github.com/AXKuhta/ObscureServer/blob/master/thread_local_storage.c#L4-L12 https://github.com/AXKuhta/ObscureServer/blob/master/Parameters.bmx#L5-L8 https://github.com/AXKuhta/ObscureServer/blob/master/ServeThread.bmx#L8-L10
What do you think about making this feature usable directly from BlitzMax itself? This should remove the overhead of calling the set/get function (which is like 5 instructions, but still).
Perhaps a
Threadlocal
keyword could be used to declare a__thread
variable. Or maybeThread Local
. Or would that beThreadglobal
?