| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Mutex semaphores |
DM> If str is a global pointer, then yes, you need to protect it.
PC> str is defined in a class. The mutex semaphore seems to have fixed my
PC> traps.
Ah, so you're using C++. Couldn't tell. :-)
BTW, your code had something like: request.MutexSem() and
release.MutexSem(). Was this a typo? I'm not sure how that could work.
I have a few classes for this... a generic semaphore (it would only work
for mutex'ing...) and a 16-bit and 32-bit version of it, all in C++. You
could then have:
MutexSem ms;
ms.Open("WHATEVER.SEM"); // opens \SEM32\WHATEVER.SEM
ms.Claim(timeout_val_in_ms); // defaults to an indefinate wait
// code...
ms.Release();
For example:
ULONG someFn()
{
static MutexSem ms;
if (!ms) // if this is the first call...
{
if (!ms.Open("someFn.SEM"))
{
return NO_SEM;
}
}
ms.Claim();
// do stuff
ms.Release();
return rc;
}
I'll be adding one more class so you can have:
ULONG someFn()
{
static MutexSem ms;
if (!ms) // if this is the first call...
{
if (!ms.Open("someFn.SEM"))
{
return NO_SEM;
}
}
DoSem ds(ms);
...
return rc; // ~DoSem will release the sem AFTER the return value is set!
}
Interested? :-)
--- Maximus/2 3.01
* Origin: Tanktalus' Tower BBS (PVT) (1:342/708)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: 342/5015 61 3615/50 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™.