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
wthreads.ijs - common API
callback.ijs - using J callback
multi1.ijs - multi threads single J instance
multi.ijs - multi threads multi J instances
multi3.ijs - multi threads multi J instances multi DLL
References
- J
Calling J.DLL, User Manual
Using Synchronization, MSDN
WinForms UI Thread Invokes, Justin Rogers
Moving from the Desktop to Devices: Multithreading and the User Interface, MSDN
Invoke vs BeginInvoke, Greg Young
Programming POSIX Threads, humanfactor.com
Parallel Programming, AIX Programming
PThread Programming, IBM
pthreads Tutorial, LLN lab
Parallel Programming Theory, Notifications
JNI Development on Mac OS X, Apple TN2147, Invoking JVM from a pthread
Specific notification pattern, IBM Java
Threads and Locks, Java Language Specification
