| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Mutex semaphores |
Hallo, Phil!
*** Am 06. November 1996 um 23:00 schrieb Phil Crown an All:
PC> I have two threads that call this function. It seems to me that it is
PC> possible that the first thread can be pre-empted before completing, then
PC> a second thread calls this function and completes it before the first
PC> function has returned a value.
PC> // called by two or more threads.
PC> release.MutexSem();
PC> return rc; // A calling thread is pre-empted here before returning rc
In theory, it is possible if the priorities of the two threads differ that
much so that the second call to the function "overcomes" the
first one. Since two threads of the same process have the same priority if
not explicitly changed by the parent, this is quite improbable.
Each thread has its own stack, though, so that function-local data is not
disturbed. Your problem comes into reality if you have to modify a global
return value variable.
I realize by now, that the called function is not the thread function
itself. You don't have a problem here either, since the value to return is
stored on the stack, i.e. a new instance will be created for each call to
the function.
This is a design problem anyway, I think. I would rather protect the call
in the thread function with a semaphore as to prevent the thread function
from calling the other function more than once.
void thread(...) {
request();
rc=function();
release();
}
Tschau...Thomas
--- E3-32/1.11-32/2.51+
* Origin: Die TeX-Box +49-6034-930021 V.34 -930022 ISDN 24h (2:244/1130.42)SEEN-BY: 50/99 270/101 620/243 625/160 711/401 409 410 413 430 808 809 934 SEEN-BY: 711/955 712/407 515 624 628 713/317 800/1 @PATH: 244/1130 24/999 888 396/1 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™.