The NXT implicitly supports multi-threading, thus an NBC thread directly corresponds to an NXT thread. Threads are defined using the thread keyword with the following syntax:
thread name // the thread's code is placed here endt
The name of the thread may be any legal identifier. A program must always have at least one thread. If there is a thread named "main" then that thread will be the thread that is started whenever the program is run. If none of the threads are named "main" then the very first thread that the compiler encounters in the source code will be the main thread. The maximum number of threads supported by the NXT is 256.
The body of a thread consists of a list of statements and optional data segments. Threads may be started by scheduling dependant threads using the precedes or follows statements. You may also start a thread using the start statement. With the standard NXT firmware threads cannot be stopped by another thread. The only way to stop a thread is by stopping all threads using the stop statement or by a thread stopping on its own via the exit and exitto statements. Using the NBC/NBC enhanced firmware you can also stop another thread using the stopthread statement.
thread main precedes waiter, worker // thread body goes here // finalize this thread and schedule the threads in the // specified range to execute exit // all dependants are automatically scheduled endt thread waiter // thread body goes here // exit // exit is optional due to smart compiler finalization endt thread worker precedes waiter // thread body goes here exit // only one dependent - schedule it to execute endt