Multi-Threading with Objects

The following rules apply when using threads and objects together.

  1. All events generated by an object are reported to the thread that owns the object and cannot be detected by any other threads. A thread owns an object if it has created it or inherited it. If a thread terminates without destroying an object, the ownership of the object and its events passes to the parent thread.
  2. The Root object '.' and the Session object ⎕SE are owned by thread 0. Events on these objects will be only be detected and processed by ⎕DQ running in thread 0, or by the implicit ⎕DQ that runs in the Session during development.
  3. Several threads may invoke ⎕DQ concurrently. However, each thread may only use ⎕DQ on objects that it owns. If a thread attempts to invoke ⎕DQ on an object owned by another thread, it will fail with DOMAIN ERROR.
  4. Any thread may execute the expression ⎕DQ '.', however:
    1. In thread 0, the expression ⎕DQ '.' will detect and process events on the Root object and on any Forms and other top-level objects owned by thread 0 or created by callbacks running in thread 0. The expression will terminate if there are no active and visible top level objects and there are no callbacks attached to events on Root.
    2. In any other thread, the expression ⎕DQ '.' will detect and process events on any Forms and other top-level objects owned by that thread or created by callbacks running in that thread. The expression will terminate if there are no active and visible top level objects owned by that thread.
  5. A thread may use ⎕NQ to post an event to an object owned by another thread, or to invoke the default processing for an event, or to execute a method in such an object. This means that the following uses of ⎕NQ are allowed when the object in question is owned by another thread:

          ⎕NQ object event...
          0 ⎕NQ object event...
          2 ⎕NQ object event...
          2 ⎕NQ object method...
          3 ⎕NQ ole_object method...
          4 ⎕NQ activexcontrol event...
    
    The only use of ⎕NQ that is prohibited in these circumstances is
          1 ⎕NQ object event...
    
    which will generate a DOMAIN ERROR.
  6. While a thread is waiting for user response to a strictly modal object such as a MsgBox, FileBox, Menu or Locator object, any other threads that are running remain suspended. APL is not able to switch execution to another thread in these circumstances.