libports/manage-multithread.c: Add #include <mach/thread_switch.h> (ports_manage_port_operations_multithread): Make threads depress their priority on startup. --- libports/manage-multithread.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/libports/manage-multithread.c b/libports/manage-multithread.c index 82fa2ac..2c690d2 100644 --- a/libports/manage-multithread.c +++ b/libports/manage-multithread.c @@ -23,6 +23,7 @@ #include <assert.h> #include <cthreads.h> #include <mach/message.h> +#include <mach/thread_switch.h> void ports_manage_port_operations_multithread (struct port_bucket *bucket, @@ -123,6 +124,16 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket, int timeout; error_t err; + /* XXX To reduce starvation, the priority of new threads is initially + depressed. This helps already existing threads complete their job + and be recycled to handle new messages. The duration of this + depression is made a function of the total number of threads because + more threads implies more contention, and the priority of threads + blocking on a contented spin lock is also implicitely depressed. + The lock isn't needed, since an approximation is sufficient. */ + timeout = (((totalthreads - 1) / 100) + 1) * 10; + thread_switch(MACH_PORT_NULL, SWITCH_OPTION_DEPRESS, timeout); + if (hook) (*hook) (); -- 1.7.10.4