| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Semaphore |
On Sunday, 96/07/21, Russell Coker wrote to Denis Tonn about "Semaphore" as follows: RC> It really depends on how many threads will be blocked on the resource RC> and how many will be blocked on other things. In one of my RC> programs which typically has about 10 threads I use critical RC> sections because I believe that it would waste CPU time if all RC> threads used semaphores when accessing certain data structures. All RC> I have to do is to use DosEnterCritSect() whenever I'm doing RC> something that requires exclusive access to the data and I don't RC> need to worry about semaphores in the other threads. Hi Russell, The overheads of calling DosEnterCritSec() and DosExitCritSec() will be slightly higher than DosRequestMutexSem() and DosReleaseMutexSem() because of all the dispatcher checking involved to determine currently ready threads. A mutex is a simple lock word with a queue. Since you need to make one API call prior to using a resource and another after you're done with it, you end up making the same number of API calls, but you've chosen the more expensive API. Your active thread will be slower than if you used mutexes and it will block other threads unnecessarily. The other threads don't need to call the API's unless they need the same resource. RC> One thing that RC> makes it easy for me to do this is that all the threads are blocked RC> on IO for >99.9% of the time, this means that it's quite acceptable for a RC> thread to lock all the other threads out for a few milliseconds as RC> they are probably blocked anyway. Being blocked on I/O is irrelevant. It doesn't matter to such a thread whether the working thread is using a mutex or a critical section. It is when another thread is ready to run that the choice is important. When an I/O-blocked thread becomes ready to run, the thread in a critical section blocks it unnecessarily, whereas the newly ready thread would get the next dispatch if the older thread were merely holding a mutex. [Unless priorities dictated otherwise.] RC> A system call takes more CPU time than 1000 user-mode instructions. The RC> fewer OS calls you make the faster your program will run and the RC> lower the pulse rating will be. What's an 'instruction' in this context? An API call is expensive compared to a non-API statement in C/C++, PL/I, FORTRAN, etc., but judicious choice of API calls can make your program run faster. Regards Dave * KWQ/2 1.2i * Clinton's Special Forces: The Pink Berets. --- Maximus/2 3.01* Origin: DoNoR/2,Woking UK (44-1483-725167) (2:440/4) SEEN-BY: 50/99 270/101 620/243 625/100 711/401 409 410 413 430 808 809 934 SEEN-BY: 711/955 712/407 515 624 628 713/888 800/1 @PATH: 440/4 141/209 270/101 712/515 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™.