Hi.

I'd like to comment a few points (please, correct me if I'm wrong):

Papi:

>        here is a little programm that works pretty well. Note that the
> sleep part is to allow other Threads to take over the cpu for a while.
> There are other ways to achieve this, but this one is, to my opinion, the
> simplest one:

I think that yield() is as simple as sleep(1) and it can do better: sleep(1)
will make your thread sleep even if there are no more threads to run. yield()
will do it only if there are other (same or higher priority?) threads to run.

Michael:

> Well, you are just assuming that threads of equal priority will switch
> between each printout in your code.
>
> In fact, the Java spec says that threads do not have to yield unless they
> are blocked by something (I/O or a monitor lock or...)

That's perfectly right and, therefore, I think I can conclude that this is not:

> As such, a large time slice or a very fast bit of code would make your
> little test have the 100 lines of output per thread happen all in one
> timeslice.  (Depending on the buffering in the output stream, this is
> not hard to do in today's hardware)

Because even if your thread takes more than a timeslice to run, it will be
perfectly able to continue so. Is that right?

Best regards,
-- Cassino


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to