User:Oleg Kobchenko/Threads
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
- File:Wthreads.ijs - common API
- File:Callback.ijs - using J callback
- File:Multi1.ijs - multi threads single J instance
- File:Multi.ijs - multi threads multi J instances
- File:Multi3.ijs - multi threads multi J instances multi DLL
References
J::
Windows::
- Using Processes and Threads, MSDN
- Using Synchronization, MSDN
- Multiple Threads in the User Interface, MSDN
.NET::
- Guidelines for Asynchronous Programming, MSDN
- Asynchronous Programming Design Patterns, MSDN2
- Overview of .NET multithreading
- WinForms UI Thread Invokes, Justin Rogers
- Moving from the Desktop to Devices: Multithreading and the User Interface, MSDN
- Invoke vs BeginInvoke, Greg Young
POSIX Threads::
- Programming POSIX Threads, humanfactor.com
- Parallel Programming, AIX Programming
- PThread Programming, IBM
- pthreads Tutorial, LLN lab
- Multi-Threaded Programming
- Parallel Programming Theory, Notifications
Java::
- JNI Development on Mac OS X, Apple TN2147, Invoking JVM from a pthread
- Specific notification pattern, IBM Java
- Threads and Locks, Java Language Specification
- invokeLater