Threaded


Syntax
Threaded[.<type>] <variable[.<type>]> [= <constant expression>] [, ...]
Description
Threaded allows to create a thread based persistent variable, arrays (except multi-dimensional arrays), lists or maps. This means every thread will have its own version of the object. This is only useful when writing multithreaded programs. If a type is specified after Threaded, the default type is changed for this declaration.

Each variable can have a default value directly assigned to it, but it has to be a constant value. When declaring a threaded array, the dimension parameter has to be a constant value.

A Threaded object can't be declared in a procedure, its scope is always global.

Example: With variables

  Threaded Counter
  
  Counter = 128
  
  Procedure Thread(Parameter)
    
    Debug Counter ; Will display zero as this thread doesn't have used this variable for now
    Counter = 256
    Debug Counter ; Will display 256
    
  EndProcedure
  
  Thread = CreateThread(@Thread(), 0)
  WaitThread(Thread) ; Wait for thread ending
  
  Debug Counter ; Will display 128, even if Counter has been changed in the thread