Tasks (Threads)

Realsoft 3D uses multi-threading to take advantage of SMP and distributed computing in general. Basic multi-threading object is called a task. A task object is created:

    #include <oops/r3task.h>

    void asyncfn(int param1, char *param2)
    {
        ...
    }

    thread = R3New(R3CLID_TASK,
                   R3TA_Code, myfunc,
                   R3TA_Priority, R3TPRI_BELOWNORMAL,
                   R3TA_Param, 5,
                   R3TA_Param, "foo",
                   R3TAG_END);

There are two ways of terminating the created threads:

Note: due to multi-threading, you have to write re-entrant code. Two or more threads must be able to run your code simultaneously. Also, when using multi-threading, shared resources must be arbitraded. Realsoft 3D uses two type of access for shared resources: mutually exlusive (write) access and shared (read) access. Correspondingly, every method in multi-threaded code is classified to be either "write" or "read" of type. R3RM_GET is a typical "read" method that any number of threads should be able to call simultaneously. R3RM_SET is "write" type of method and only one thread should be able to run it simultaneously.

When Realsoft 3D is started the main thread initializes the application context (R3APP), loads all libraries and registers their classes and then enters the event processing loop for runnign the user interface code. So generally only the class and user interface specific data is quaranteed to run single threaded. Correspondingly, only the class and user interface code can use code that is not re-entrant (use static and public variables, for example). Pretty much everything else should be re-entrant.