TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Peter Fitzsimmons
from: James R. Cook
date: 1997-01-11 01:22:59
subject: DosRead blocking

-=> Quoting Peter Fitzsimmons to James R. Cook <=-



 JRC>  :)  I understand.  *sigh*  Is there an alternative to using Mutex

 JRC>  semaphores?  They seem to take a *LONG* time to lock/unlock (or is that

 JRC>  block/unblock).  I recall seeing some code that used 

 JRC> the DosEnterCritSec



 PF> Forget that function exists.



 :)  Okay, what was that function again ...?



 PF> IBM's compiler has a great set of undocumented semaphore functions (or

 PF> you can roll your own,  but you _must_ use a little assembly language

 PF> for the LOCK prefix (to make it SMP safe)). 

 PF> These type of semaphores use a local flag to keep a lock count (and

 PF> this is the flag that requires the intel LOCK prefix).  Only when the

 PF> lock count is greater than zero,  does the "fast
semaphore" code call

 PF> an OS/2 sem api to handle it (You want to call an OS/2 api here,  and

 PF> not your own "wait" function,  so that the os/2 schedular
can do its

 PF> magic). 

 PF> Rolling your own code for this was easy under OS/2 1.x,  but got a

 PF> little complicated under OS/2 2.x (because you have to use two types

 PF> of semahpores). 

 PF> The reasoning is:  Since a collision is rare,  especially when you

 PF> only have one cpu,  why call DosSem function every

 PF> time? Avoid the call by keeping a local flag

 PF> indicating whether or not a collision has taken

 PF> place. 

 PF> DosEnterCritSec() is the other extreme;  it assumes

 PF> every thread in your program has collided (asked

 PF> for access to the same resource) at the same time,

 PF> even if the other threads never use it!



 That's what I was wondering about ... that makes perfect sense!



 PF> A "fast semaphore" is faster than DosEnterCritSec()

 PF> anyway.



 Hmph.  Now, what's a reasonable way to go about this?  That's why I was

 asking about the different threads for the comm i/o.  It would seem to

 make the code cleaner / more efficient to do away with the threads and

 just do some old-fashioned procedural coding.  *sigh*  Life is just so

 complicated with these modern operating systems ... ;)



 ={) James (}=



--- Blue Wave/DOS v2.30

* Origin: COMM Port OS/2 juge.com 204.89.247.1 (281) 980-9671 (1:106/2000)
SEEN-BY: 50/99 54/99 270/101 620/243 625/0 160 711/401 409 410 413 430 808
SEEN-BY: 711/809 934 955 712/311 407 505 506 517 623 624 704 841 713/317
SEEN-BY: 800/1
@PATH: 106/2000 396/1 270/101 712/624 711/808 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™.