| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Mutex semaphores |
Is this the proper way to use a Mutex Semaphore to protect a resource?
I have two threads that call this function. It seems to me that it is
possible that the first thread can be pre-empted before completing, then
a second thread calls this function and completes it before the first
function has returned a value.
ULONG someFn()
{
request.MutexSem();
ULONG rc = 0;
rc = something;
str = somethingtoo; // this also needs protecting because str is
// used in another function that is also
// called by two or more threads.
release.MutexSem();
return rc; // A calling thread is pre-empted here before returning rc.
// A second threads comes along and completes the
// function before the first thread has finished,
// thus causing rc to contain invalid data.
// Is this possible?
}
Phil Crown
pcrown{at}airmail.net
http://web2.airmail.net/pcrown/
--- Blue Wave/OS2 v2.30
* Origin: * MacSavvy OS/2 BBS * Dallas, Texas * 972-250-4479 * (1:124/1208)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: 124/1208 1 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™.