|Title||Multiple thread registration does not work on all platforms|
|Assigned user||Richard Brooksby|
|Description||It's not clear from the documentation or code whether registering a thread more than once is permitted, or whether it needs to be supported.|
(Originally reported by Tony Mann .)
|Analysis||request.dylan.160252  shows that this feature is needed to support the situation where a program that does not use the MPS is calling into MPS-using code from multiple threads. On entry to the MPS-using code, the thread can be registered, but it may not be possible to ensure that the thread is deregistered on exit, because control may be transferred by some non-local mechanism such as an exception or longjmp. It would not be acceptable to insist that the client program keep a table of threads it has registered, because maintaining the table might require allocation, which might provoke a collection. In addition, each entry point might be at a different position in the stack and so require a root with a different stack base.|
Does multiple registration work? Here's an analysis:
On XC, we use the Mach calls thread_suspend and thread_resume , which increment and decrement the thread's suspend count, so it does not matter how many times a thread is registered (all that happens is that there are some wasted calls). However, the actual registration fails with
protxc.c:341: MPS ASSERTION FAILED: old_exception_ports == MACH_PORT_NULL
On W3, we use SuspendThread  and ResumeThread  which also increment and decrement the thread's suspend count.
On LI and FR, we take care not to suspend and resume a thread more than once (threads with the same thread id go onto a idRing when suspended). See pthrdext.c . Note that this means that thread suspension is O(n^2).
On AN, the second attempt to register the thread causes an assertion failure. (Fixed in change 187354.)
|Evidence|| "Better snowmen: proposed solution" <|
|Created by||Richard Brooksby|
|Created on||2013-07-17 14:34:52|
|Last modified by||Gareth Rees|
|Last modified on||2016-09-04 14:23:07|
|History||2013-07-17 RB Created.|
|192127||closed||2016-09-04 14:23:07||Gareth Rees||Support registering a thread with the MPS multiple times on OS X.
Restore test case.
|187354||open||2014-10-22 20:42:56||Gareth Rees||Complete design.mps.thread-manager and move it from old to current.
Better description of protection mutator context module in the "porting" chapter.
The generic thread manager mustn't assert that there is only one thread -- this would break design.mps.thread-manager.req.register.multi.
|183114||open||2013-07-17 14:38:05||Richard Brooksby||Removing false comment about multiple thread registration, but see job003559.
Imported from Git
Author: Richard Brooksby <email@example.com> 1374068285 +0100
Committer: Richard Brooksby <firstname.lastname@example.org> 1374068285 +0100