Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Jan 100 07:58:17 +0200 (SAT)
From:      Reinier Bezuidenhout <rbezuide@oskar.dev.nanoteq.co.za>
To:        jasone@canonware.com (Jason Evans)
Cc:        wes@softweyr.com, hackers@FreeBSD.ORG
Subject:   Re: Preemptiveness of FreeBSD threads
Message-ID:  <200001170558.HAA19865@oskar.dev.nanoteq.co.za>
In-Reply-To: <20000116214416.S302@sturm.canonware.com> from Jason Evans at "Jan 16, 0 09:44:16 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
Hi ...

I also ran this program on a 4.0-current as of about Jan 13 2000 :)

It generates the errornous output like clock work on my machine (after about
30 tries - no exception).  I then though that maybe the system gets so buzy
that it has difficulty on starting the threads - yes I know this should not
be a problem.

I added a "sleep (1);" as the FIRST instruction in the "start_my_thread"
functioni (Thus it is not inside the loop).  This causes the following
output every time.

jarrow# ./thread
^C
Thread 0x00: 6524518
Thread 0x01: 6574627
Thread 0x02: 6605728
Thread 0x03: 12928447
Thread 0x04: 6327346
Thread 0x05: 6592751
Thread 0x06: 12971487
Thread 0x07: 12968330
Thread 0x08: 6567584
Thread 0x09: 6642237
Thread 0x0a: 12632004

Ok :) not the EXACT same output put you know what I mean.  Interesting,
if I press ctrl-c too erly I sometimes get

jarrow# ./thread
^C
Thread 0x00: 6469560
Thread 0x01: 6541408
Thread 0x02: 12888010
Thread 0x03: 6327606
Thread 0x04: 13160549
Thread 0x05: 6005825
Thread 0x06: 12345878
Thread 0x07: 0
Thread 0x08: 0
Thread 0x09: 0
Thread 0x0a: 12974910

It seems that letting it wait a while before entering the loop causes all
the thread to get time to startup and start counting

Reinier

> > Yup, that does it, but it makes the program several orders of magnitude slower,
> > too.  Be careful about how much you use sched_yield, you're pushing the system
> > into behavior that is outside its normal operating design.  FreeBSD wasn't 
> > designed to re-run the scheduler after 2 or 3 instructions.
> 
> In the case of libc_r, a call to sched_yield doesn't result in the system
> call sched_yield.  Rather, it causes the userland threads scheduler to be
> run.  There is still plenty of overhead, but running the kernel scheduler
> isn't necessarily part of that overhead.
> 
> Jason
> 
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-hackers" in the body of the message
> 



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200001170558.HAA19865>