Hi all,
I pushed a sequence of changes just now to simplify plan9port.
1. Pthreads are required. We were already using pthreads on every platform but NetBSD, where the build had been broken for months. Now we use it on NetBSD too, and hopefully the build is fixed there.
2. Every thread in libthread is now its own pthread. The threads are still cooperatively scheduled within their procs as before, to avoid introducing races. That is, only one pthread within a proc group is ever executing at a time. It's a bit of a waste of pthreads, but operating systems can handle lots of pthreads now, and plan9port programs were not creating lots anyway. Putting each thread in its own pthread lets each run on its own system stack, using the default pthread stack size - the various configurable stack sizes in the libthread API are now completely ignored. Putting each thread in its own pthread means we don't have to depend on having working makecontext/swapcontext routines, which work less and less often. And putting each thread in its own pthread means that all threads are easily visible to debuggers like gdb or lldb with 'thread apply all where' or 'bt all'.
3. Libthread programs that intend to run in the background by having all threads in the main proc exit, leaving behind threads in non-main procs, must declare this intention by defining:
int
threadmaybackground(void)
{
return 1;
}
If they don't, then instead of backgrounding when the last thread in the main proc exits, the program will sysfatal with the message "threads in main proc exited w/o threadmaybackground". This is documented in thread(3). See
7457774 for an example.
4. The spurious parent process for most threaded programs is gone. The parent process was created just in case the program tried to background itself. Now it is only created when threadmaybackground returns non-zero (there is a default returning zero provided by libthread for programs that don't declare one like above). This mainly affects ps listings and running programs under debuggers.
5. Assembly is gone. Requiring pthread-per-thread mode allowed deleting all the custom makecontext/swapcontext implementations, and the tas-based lock implementations were already gone. The only remaining assembly was a bit of 386-specific code for libmp and libsec, but all the other architectures were using portable C code, and the 386 can too. So that's all gone, along with the 9a program. If you have a program with assembly to assemble with the system assembler, you can set AS= in your mkfile after <$PLAN9/src/mkhdr. Without the AS=, the mkfile will try to run 'no-9a', which should be an obvious clue.
The motivation for all this cleanup was getting threaded programs running on the new Apple M1 toolchains. Threaded programs broke in subtle ways using makecontext/swapcontext but worked fine in pthread-per-thread mode. We've debugged buggy implementations of those routines - not to mention other broken tools that assume there's no stack switching outside of pthreads - for long enough. No more.
The simplifications should help with the next port too, whatever that is.
All that said, there are probably new bugs introduced. Please file issues if you run into any problems.
Thanks, and happy new year!
Best,
Russ