User:Oleg Kobchenko/Threads

From J Wiki
Jump to navigation Jump to search

Assumptions

  • One thread is one stack
  • J instance is single-threaded
  • A process can host multiple independent J instances
  • Theoretically, J process could have multiple GUI message loops, one per thread; in reality only the master instance on main thread has the message loop; slave instances should use explicit wait to receive notifications or become inactive (exit execution) to be reused

Thread Control

  • Create J instance
  • Create thread: start execution or in suspended mode
    • populate slave instance with code names synchronously from master
    • initiate execution using callback allocated in slave
  • Suspend / resume execution
  • Destroy thread / exit execution

Synchronization

  • Mutexes
  • Locking
  • WaitForMultipleObjects (win32)
  • Common variables, mapped files

Notifications

  • Conditional variables (pthreads)
  • Events (win32)
  • Polling, timer, explicit wait, irresponsive GUI
  • Using message loop, faking GUI events
  • SIGNALs, sockets

Examples

All files are placed under user/threads

References

J::

Windows::

.NET::

POSIX Threads::

Java::