Register to post in forums, or Log in to your existing account
 

 Related 
Contents
Threads
  #RESUME
  #SECTION
  #SIGNAL
  #STOP
  #SUSPEND
  #THREAD
  #WAIT
  #WAITFOR
  #WAITSIGNAL
  #WAITTHREAD
  %section
  %threadid
  %threadname
Feature Reference
  Aliases
  Macros
  Variables
  Functions
  Classes
  Triggers
  Buttons
  Gauges
  Paths
  Menus
  Events
  Modules
  Windows
  Packages
  Shared Package Library
  Package Editor
  Docked Windows
  Customizeable Toolbars
  Sessions
  Expressions
  Automapper Module
  Database Module
  Syntax Checking
  Tab Completion
  Status items
  Preferences
  Simutronics Support
  Pueblo Emulation
  Keyboard shortcuts
  MXP
  Threads
  ATCP
  Script Debugger
  Timestamps
  Lua Scripting
Related Links:
  New Features
  #SECTION
Threads [[cmud_threads]] 
Added in v2.0
Since version 2.0, CMUD is completely multi-threaded. This has both advantages and disadvantages. The advantage of being multi-threaded is that CMUD can run multiple scripts in parallel for improved performance and more advanced functionality. The disadvantage of being multi-threaded is that scripts which run in parallel need to be more careful about accessing or modifying global resources (such as variables).

In normal scripting and normal use, you will not notice any changes resulting from CMUD being multi-threaded. By default, CMUD will still execute commands, triggers, and other scripts in sequential order, just like in versions prior to 2.0.

However, certain "wait" commands can now be used to suspend the current thread, allowing it to wait in the background before continuing. When the thread continues at a later time, it will be running in parallel with any other commands, triggers, or scripts.

The commands that will cause a thread to suspend itself are: #WAIT, #WAITFOR, #WAITTHREAD, #WAITSIGNAL, and #SUSPEND. If you use any of these commands in your script, then you should make sure that the rest of the script following the wait command is "thread-safe".

To make a script "thread-safe", you should protect any access of a global resource, such as a global variable, using the #SECTION command. This will create a named "protected" section of code, and only one thread can execute a named section at a time.
Viewer Comments [0 - Post your comments]

Jump to:  

© 2009 Zugg Software. Hosted by Wolfpaw.net