Commit Graph

59 Commits

Author SHA1 Message Date
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 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
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
Russ Cox 4197af4122 libthread: comment stack border a bit more 2020-01-24 13:09:55 -05: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 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 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
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 b32d9d9c2e libthread: remove bogus write in threadmain 2008-02-28 08:49:34 -05:00
rsc df970459f9 pin 2006-06-26 05:47:59 +00:00
rsc d93cc14ece fix proc leak; add p9usepwlibrary 2006-06-12 17:20:42 +00:00
rsc af6e459f18 put threadinfo back 2006-04-21 03:58:52 +00:00
rsc 110c707dda darwin 386 start 2006-04-21 03:34:44 +00:00
rsc cbeb0b26e4 Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
rsc 615e0f9fb2 add threadidle 2006-02-07 17:02:05 +00:00
rsc 9eda38e51f add threadid 2006-02-05 17:50:09 +00:00
rsc 6dde87f83c Print information on SIGQUIT, SIGINFO. 2005-09-26 12:05:26 +00:00
rsc 5b0927915f Log if _threaddebuglevel is set. 2005-09-26 11:37:49 +00:00
rsc d08f40666b sun 2005-07-27 13:06:50 +00:00
rsc 2b6040818e use full prototypes 2005-05-07 22:42:14 +00:00
rsc 0ba4eb47d4 no need to setproc(0) 2005-03-18 19:05:50 +00:00
rsc 8dd8a81f71 add threaddata 2005-03-18 18:56:17 +00:00
rsc d7688cce37 add check for procscheduler returning 2005-02-16 17:15:56 +00:00
rsc 80b8842f3e hard-to-find locking bug 2005-02-15 18:08:28 +00:00
rsc 8ee6ad4d96 different fix for main proc bug 2005-02-14 18:58:56 +00:00
rsc 8f4871fd2e work around stupid linux bug 2005-02-13 18:35:19 +00:00
rsc 1fdb4a5450 rename scheduler to have a more distinctive name, so stack traces can end there 2005-01-23 22:57:53 +00:00
rsc a0e8d02d09 Apparently SuSE 9.1's X distribution uses even bigger
buffers than the standard ones.  64kB appears to be enough
for a stack in that case, but let's just go nuts and make
the stacks enormous, so that it takes a few more doublings
of X's stack needs before we run into this problem again.

The VM system should take care of not actually using most
of the memory anyway.
2005-01-23 16:02:04 +00:00
rsc 803292c631 proccreate race 2005-01-18 20:53:12 +00:00
rsc 515b6e5bff add threadgetname 2005-01-18 20:17:12 +00:00
rsc 8650250482 64-bit nonsense 2005-01-18 05:57:35 +00:00
rsc 0b561695d6 useful warning comment 2005-01-16 21:31:21 +00:00
rsc 2b3b1e8984 oops sunos 2005-01-14 18:11:21 +00:00
rsc c8b6342d3c Many small edits. 2005-01-13 04:49:19 +00:00
rsc 37cc72d323 paranoia 2005-01-11 21:28:00 +00:00
rsc b8f742db85 os x changes 2005-01-11 17:43:53 +00:00
rsc 1aa9c533e0 allow lock passing 2005-01-07 20:52:07 +00:00
rsc a0a331aad9 add _procwakeupandunlock
to help ease locking contention
on Linux 2.4.
2005-01-06 23:43:42 +00:00
rsc af89fc108d more debugging 2005-01-06 23:07:19 +00:00
rsc 15cd8255b5 more debugging 2005-01-04 22:22:18 +00:00
rsc 1d2533d010 restore old plan 9 property that when the
last thread exits the main proc, the remaining
program ends up in the background and the
program appears to have exited.
2004-12-28 22:36:24 +00:00