Multi-Threading

Realsoft 3D is multi-threaded and all time consuming tasks are distributed into all available processors and cpu cores. Due to the multi-threaded nature of the software all code should be re-entrant. Two or more threads should be able to run code simultaneously. Only the user interface and application initialization specific code is quaranteed to be single thread (the user interface / event processing is run by the main thread).

The key point in multi-threaded coding is re-entrancy. Any number of thread can run re-entrat code simultaneously, without worrying about interfering the execution of other threads, and hence harness all the processing power available.

All shared objects (objects more than one thread can manipulate simultaneously) must be arbitraded via semaphores that support two type of access: mutually exclusive read lock and shared read lock. This allows any number of threads to read the shared resouces but only one thread to change it.

Because the system that uses multi-threading must know whether to use shared read lock, or mutually exclusive write lock, all methods should be classified as 'read' and 'write'. A typical 'write' method is SET and a typical example of read access is GET. Any number of threads must be able to read data simultaneously.

Shared resources must not be locked longer than necessary.

When a thread attemps to access more than one shared resource simultaneously a situation called dead lock can arise. In dead lock two threads wait each other indefinitely. To avoid dead locks the system managing the shared resource must also specify the order in which the resources can be accessed. Every thread that needs to lock more than one resource simultaneously must follow this common locking order.