[M3devel] Cooperative suspend?

Jay K jay.krell at cornell.edu
Sun Jan 19 13:00:01 CET 2014

Windows uses SuspendThread.
I'll double check.

Cooperative suspend would NOT involve sending a "signal" to threads, in the Posix sense.
Nor would it use SuspendThread.

The model for cooperative suspend has been described by Tony and goes something like this:

There is a list of threads maintained by the m3 runtime.
  Not by enumerating OS threads.
The thread structure contains in it perhaps a boolean or enum as to suspend requested, suspending, suspended, resuming, running, etc.

When a thread wants to collect garbage, it either walks the thread list and sets all the booleans/enums to "suspend requested", or, more likely, it sets one global boolean.

Now, there are three likely methods to set the global boolean.
 1 - it is a global writable variable 
 2 - it is a global writable function pointer 
 3 - it is a page with protection 

Code frequently polls this global boolean, in one of the following fashions
 1 - read and test the value of the variable 
 2 - call the function pointer 
 3 - read the page (just a byte or a word) ignoring the contents 
 4 - call a function to do any of the above, esp #1 

#3 is probably fastest but my least favorite. It has lingering portability problems and is slowest when it comes time to actually suspend -- catch the exception and for purposes of debugging, you really don't want a design that raises exceptions like that.

When does the polling occur?
The polling is generated by the compiler.
It is done at function entry and/or exit and at branches or at least backward branches or at least branches that are continuing loops or such or at the starts of loops or somesuch.

I believe Java uses cooperative suspend and I think it uses the page protection mechanism.
It isn't portable e.g. to systems without an MMU.
Though of course you could abstract it out.

I'm glossing over details, but you know all the code we have for signals and semaphores? It goes away.
Our portability then would drive one more significant notch toward that of "hello world".

In my mine, we have about two pieces to do to gain "hello world" level of portability
  - cooperative suspend, not easy  
  - jmpbuf size removal, should be easy  

and some small matters
  - endianness, particularly in the libary 
  - word size 

 - Jay

From: dragisha at m3w.org
Date: Sat, 18 Jan 2014 09:24:11 +0100
To: m3devel at elegosoft.com
Subject: [M3devel] Cooperative suspend?

What exactly do you mean? Isn't it cooperative already? Thread stopping the world informs others about its intent, and they suspend themselves on a semaphore. Windows implementation of threading does forced suspend?

--Dragiša Durićdragisha at m3w.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20140119/88389edf/attachment-0002.html>

More information about the M3devel mailing list