Thread support in 0.10 on OpenBSD

Miller Abel miller.abel at solopoint.com
Tue Mar 31 16:33:53 PST 1998


Robert S. Thau Wrote:
> it reduced the necessary assembly coding to one line (plus a few
pseudo-ops)

It seems that a number of us have been down this path before. I wrote a
thread scheduler for my company's desktop PBX device. "C" on an embedded
68K.

If assembler is permitted, a simpler and more maintainable solution is
to use a single line of assembler to load the initial stack pointer
value when a thread is created. Then all that is required is
setjmp/longjmp. The jmp_buf structures are simply saved with the thread
data (and one for the scheduler context) and are neither inspected nor
modified.

For a 68K with Microtec C:

                asm(" move.l _tasksp,sp ");

loads the stack pointer with the malloc'ed value in _tasksp.

The scheduler executes (sched_jmp_buf = setjmp()) to save the kernel
context before activating a thread. A thread calls setjmp() before
yielding to save its own context then calls longjmp(sched_jmp_buf) to
yield to the scheduler.

It is probably simpler to determine the proper line of assembler needed
to load the stack pointer than it is to figure out how the jmp_buf for a
particular environment is structured.

Miller.


More information about the kaffe mailing list