TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Alan Clifford
from: Peter Fitzsimmons
date: 1996-03-21 04:25:00
subject: Threads

AC> I was expecting thread 2 to print a few lines then swap to thread 3, 
 AC> print a few lines and so on.  But it can get stuck in 
 AC> one of the threads for about 19 seconds.  I also

The problem is that your threads to not call anything that
"blocks". Whenever a thread calls something that blocks,  OS/2
looks for a thread with a higher priority that is ready to run (perhaps
because its MAXWAIT period expired).  Eventually OS/2 will pre-empt the
thread,  but such occurances should be rare in a well written native OS/2
program.

A blocking call is one that waits for something:  A keystroke,semaphore,
disk (device) read/write.

Your C runtime is also involved here.  I don't have EMX installed,  but
IBM's VAC++ 3.0 buffers stdout in a similar way,  so your sample program
seems to have the same behavior.  Watcom 10.0,  on the other hand, calls
DosWrite() after each '\n',  so the behavior is much different -- unless I
redirect stdout to a file,  in which case (because of the disk cache),it
reverts to the behavior you described.

In your particular case, if you want a perfectly smooth running
program,place a DosSleep(1) (or maybe DosSleep(0)) in your
"while(1)" loops.

You can also try playinf around with the buffering mode of stdout
(setvbuf() with many C compilers),  or with the size of the stdout buffer.


--- Maximus/2 3.00
* Origin: Sol 3 * Toronto * V.32 * (905)858-8488 (1:259/414)
SEEN-BY: 50/99 78/0 270/101 620/243 711/401 409 410 413 430 808 809 934 955
SEEN-BY: 712/407 515 517 628 713/888 800/1 7877/2809
@PATH: 259/414 400 99 250/99 3615/50 396/1 270/101 712/515 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.