SML# Document Version 4.0.0
29 SML# Run-time data management

29.4 Effect of multithreading

SML# allows the users to import C functions that spawns new threads. Even if SML# callback functions are called from a thread that C function creates, the SML# runtime detects the new threads and runs SML# programs concurrently in multiple threads. Similarly to the C programs, SML# uses the multithread support provided by the underlying operating system. If operating system supports parallel execution of multiple threads on multicore CPUs, SML# program using multiple threads runs in parallel.

Threads of SML# program shares a unique SML# heap. Interthread communication can be realized by updating arrays. Exclusive execution is performed by calling C function that realizes exclusive execution. Since SML# never move data on heap, you are allowed to allocate C’s semaphores and mutexes on SML#’s heap.

This is all abort SML#’s multithread support. Current SML# does not provide high-level thread library, but it is open to the users to write it in SML#. The future version of SML# will be likely to provide a parallel programming framework.