Commit graph

248 commits

Author SHA1 Message Date
Anthony Sorace
70cc6e5ba7 libthread: use setpgid instead of setpgrp 2021-04-22 08:44:27 -04:00
Russ Cox
52b599a63c libthread: call setpgrp in programs that will background
This fixes the 'run stats from rc; exit rc; stats dies' problem.
It's unclear whether this is the right fix or whether rc should
be starting all its interactive commands in their own process
groups. But at least it does fix stats dying.
2021-01-14 10:30:24 -05:00
Russ Cox
91ececc997 libthread: drop schedlock
Having two locks in the proc was causing deadlocks.
2020-12-30 08:41:01 -05:00
Russ Cox
1857120806 libthread: simplify
Now that everything uses pthreads and pthreadperthread,
can delete various conditionals, all the custom context code,
and so on. Also update documents.

Fixes #355.
2020-12-30 07:53:28 -05:00
Russ Cox
e68f07d46f libthread: make pthreadperthread the default 2020-12-30 00:20:26 -05:00
Russ Cox
b73633b1b4 libthread: fix pthreadperthread bugs 2020-12-30 00:15:37 -05:00
Russ Cox
b3a20a96eb libthread: add threadmaybackground
Programs that want to background themselves now need
to define threadmaybackground returning 1.
This avoids a confusing (to people and debuggers)
extra parent process for all the threaded programs
that will never want to background themselves.
2020-12-30 00:12:14 -05:00
Russ Cox
5b37d91264 libthread: delete NetBSD special case
I added a direct call from thread.c to pthread.c's _threadpthreadstart
in May, and no one has complained about NetBSD being broken.
So probably no one is using this on NetBSD at all.
Make pthread the only option.
2020-12-30 00:06:35 -05:00
Russ Cox
2991442aef libthread: fix use after free of first thread in each proc
This was causing sporadic but frequent crashes at startup
in 9pserve on the new M1 Macs, correctly diagnosing a
use-after-free.
2020-12-15 00:06:03 -05:00
Xiao-Yong
329831171d
libthread: use libc functions in ucontext for macOS (#417) 2020-06-15 23:18:03 -04:00
Russ Cox
162d0d5cd9 libthread: handle spurious _procsleep wakeups, fix $LIBTHREAD handling 2020-05-17 23:18:33 -04:00
Russ Cox
baef953da2 libthread: add pthreadperthread mode and use under ASAN
ASAN can't deal with the coroutine stacks.
In theory we can call into ASAN runtime to let it know about them,
but ASAN still has problems with fork or exit happening from a
non-system stack. Bypass all possible problems by just having
a full OS thread for each libthread thread. The threads are still
cooperatively scheduled within a proc (in thos mode, a group of OS threads).

Setting the environment variable LIBTHREAD=pthreadperthread
will enable the pthreadperthread mode, as will building with
CC9FLAGS='-fsanitize=address' in $PLAN9/config.

This solution is much more general than ASAN - for example if
you are trying to find all the thread stacks in a reproducible crash
you can use pthreadperthread mode with any debugger that
knows only about OS threads.
2020-05-17 20:15:41 -04:00
Neven Sajko
0237dec768 libthread: fix ARM build by renaming file
Fixes #363

Change-Id: Ic8ad5ccce3935fdf00732d78d3024b535db90447
2020-02-11 06:58:26 -05:00
Russ Cox
4197af4122 libthread: comment stack border a bit more 2020-01-24 13:09:55 -05:00
Russ Cox
f6c9f7b14c libthread: fix test deps, cleanup in mkfile 2020-01-19 23:04:58 -05:00
Russ Cox
4698bde236 libthread: clean up sysofiles.sh a bit more 2020-01-19 23:04:58 -05:00
Russ Cox
37e7d24c0c libthread: rm OpenBSD tas implementations
OpenBSD is using pthreads now, so no need for tas.
2020-01-19 23:04:58 -05:00
Russ Cox
41b3e8b989 libthread: use consistent stack calculation code in makecontext
Also reduce duplication: makecontext is per-arch not per-os-arch.

May fix #353.
2020-01-19 23:04:58 -05:00
Russ Cox
ac8042dfa9 libthread: rm NetBSD pthread reference in sysofiles.sh
It may be that pthreads on NetBSD is now good enough,
but the build as written (introduced in 23a2368 at my suggestion)
is certainly broken, since both NetBSD.c and pthread.c define
the same functions.

If NetBSD does support pthreads now, then a few things
should happen together:

 - libthread/sysofiles.sh should drop its top NetBSD case entirely
 - libthread/NetBSD.c should be deleted
 - libthread/NetBSD-*-asm.s should be deleted
 - include/u.h's NetBSD case should define PLAN9PORT_USING_PTHREADS
   and #include <pthread.h>

For now, restore to less clearly broken build.
2020-01-19 23:04:58 -05:00
Russ Cox
cb8f735786 all: remove Linux 2.4 vs 2.6 detection
Linux 2.4 is dead.
(The libthread code hasn't worked for Linux 2.4 for a long time.)
2020-01-19 23:04:58 -05:00
Russ Cox
8d82ccefd2 libthread: remove Linux 2.4 code
Linux.c was for Linux 2.4 and is no longer used directly,
only indirectly because NetBSD.c was a 1-line file #including Linux.c.
So mv Linux.c NetBSD.c.

Also rm Linux-*-asm.s which was for Linux 2.4 as well.
2020-01-19 23:04:58 -05:00
Russ Cox
c181e39eea libthread: rm unused sparc-ucontext.h
More dead code.
2020-01-19 21:26:30 -05:00
Russ Cox
52397aaf2b libthread: rm Darwin pre-11.0.0 support
Darwin 11.0.0 was Mac OS X 10.7.0 aka Lion.
The previous version was Snow Leopard, which
has been unsupported by Apple since February 2014.
2020-01-19 21:26:30 -05:00
Russ Cox
8dcb18f71b libthread: rm FreeBSD 4 code
Pretty sure FreeBSD 4 is gone now. :-)
2020-01-19 21:26:23 -05:00
Russ Cox
d15607b9dd libthread: rm OpenBSD.c
This should have been deleted in 20f5692b (2012-07-14),
which removed the mkfile and sysofiles.sh references to it.
2020-01-19 20:52:35 -05:00
Neven Sajko
57157d856e libthread: rm unused ARM (get|set)mcontext (#354)
They were just a duplicate of my(get|set)mcontext from the other
assembly file, and unused from threadimpl.h.

Change-Id: Id8003e5177ed9d37a7f0210037acbe55bbf7f708
2020-01-19 20:43:55 -05:00
Dan Cross
23a2368980 libthread: NetBSD supports pthreads, remove ancient systems in sysofiles.sh
Signed-off-by: Dan Cross <cross@gajendra.net>
2020-01-16 17:01:44 +00:00
Russ Cox
8c573cab68 libthread: use mmap to allocate OpenBSD stacks
Should fix faults on OpenBSD.

Fixes #218.
Fixes #226.
2020-01-14 13:58:47 -05:00
Russ Cox
481b596d93 libthread: fix fault in teardown of proc
Fixes #332.
2020-01-13 23:26:42 -05:00
Russ Cox
369923f6fc libthread: fix nbrecvul, recvul to match man page, Plan 9
They return 0 on failure, not -1.
Bug introduced in my original libthread-for-Unix code.

Fixes #230.
2020-01-13 17:00:58 -05:00
Russ Cox
0158bceec7 libthread: run first thread in proc on system stack
For pthread systems that are fussy about which stack is used,
this makes sure that threadmain runs on a system stack.
If you only use proccreate (never threadcreate), all threads run
on system stacks.
2020-01-12 15:08:28 -05:00
Dan Cross
fa325e9b42 Trivial changes: whitespace and modes.
Remote whitespace at the ends of lines.
Remove blank lines from the ends of files.
Change modes on source files so that they
are not executable.

Signed-off-by: Dan Cross <cross@gajendra.net>
2020-01-10 14:54:30 +00:00
Russ Cox
9e4b56e764 libthread: add threadspawnd
R=rsc
http://codereview.appspot.com/6742064
2012-10-22 12:32:09 -04:00
Russ Cox
220c15d2b7 fix gcc 4.7 warnings (thanks Tuncer Ayaz)
R=rsc
http://codereview.appspot.com/6744053
2012-10-20 13:36:52 -04:00
Russ Cox
20f5692b7f openbsd updates (thanks Pascal Stumpf)
R=rsc
http://codereview.appspot.com/6401049
2012-07-14 10:16:54 -04:00
Russ Cox
813b3eea8b OS X PowerPC fixes (thanks Cameron Kaiser) 2011-10-23 17:55:23 -04:00
Russ Cox
b4f9ba7894 libthread: fix 10.5.8 build - uname says 9.8.0 2011-10-14 00:01:12 -04:00
Russ Cox
04e0a9bb81 libthread: Lion context routines 2011-10-13 23:57:54 -04:00
Russ Cox
fc567f476a build: OS X 64-bit build
R=rsc
http://codereview.appspot.com/4838047
2011-08-02 14:28:04 -04:00
Richard Miller
9cf92718e9 arm: build fixes
Get p9p to build cleanly for ARM - based on suggestions from rsc and eekee, plus a final tweak from me.  Tested (a bit) on sheevaplug (ubuntu jaunty), Nokia N800 (maemo 4) and Nokia N900 (maemo 5).

R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/4524056
2011-05-18 13:20:56 -04:00
Russ Cox
ba940ae61c libthread: context switching for arm, still not complete 2009-11-18 04:12:17 -05:00
Russ Cox
fa662c9571 INSTALL: fix build on Snow Leopard
http://codereview.appspot.com/116073
2009-09-11 13:51:50 -04:00
Russ Cox
0829f75bba libthread: make page work on OS X 2009-08-17 17:29:44 -07:00
Russ Cox
0ac670585c libthread: work around gcc warning on FreeBSD 2008-12-23 13:03:07 -08:00
Russ Cox
d19769ae98 libthread: correct sysfatal handler prototype 2008-10-26 17:01:59 -04:00
Tim Wiess
69d1259cf9 libthread: add proper sysfatal 2008-07-20 03:11:05 -04:00
Russ Cox
faf1fb6c7e libthread: abort on single-threaded lock contention 2008-07-09 11:41:14 -04:00
Russ Cox
df1ee4e1af libthread: fix 64-bit bug in threadstart (Nathaniel Filardo) 2008-06-01 08:41:51 -04:00
Russ Cox
0215811dc2 libthread: fix no-receive nbrecv etc. bug (David Jeannot) 2008-05-06 12:51:19 -04:00
Russ Cox
80f2165d27 libthread: input sanity checks 2008-05-05 23:08:35 -04:00