TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: JERRY COFFIN
from: DARIN MCBRIDE
date: 1997-08-31 09:50:00
subject: volatile objects?

 -=> Quoting Jerry Coffin to Darin Mcbride
 DM> I'm unsure if you realize it, but events and semaphores are
 DM> significantly different... :-)
 JC> Actually, I am...now.  When I first wrote the code, I wasn't, and by
 JC> the time I realized my error, it would have been a pain to change.
Hmmm... when I looked at the code, it didn't look too bad to switch... mind
you, I probably have a little more experience with OS/2 semaphores, so it'd
just look easier to me.  :-)
 DM> So, is this a "go ahead and post your thread-safe [?] OS/2-based
 DM> templated circular queue"?  :-)
 JC> Something like that, yeah.
Ok, I'll try it...
 DM> (Win32 could likely get away with just using Critical Sections, but
 DM> some of the Semaphore class could only be replicated via undocumented
 DM> peeking into the CRITICALSEMAPHORE[?] structure since there is no
 DM> other way that I saw to determine who currently owns the semaphore.
 JC> Hmm...It's a CRITICAL_SECTION for a critical section, or a HANDLE for
 JC> a semaphore.  However, I'm interested in knowing why you want to know
 JC> about the owner of either.  Nearl anything you try to do with that
 JC> information is going to be subject to race conditions...
The actual code is an IsClaimed() function to see if the currently running
thread owns the semaphore.  It's primarily for assertions - make sure that we
are currently inside our semaphore... i.e.
template 
class SafeQueue
{
// ...
private:
  DoPush(const T& t)
  {
    assert(GetSemaphore().IsClaimed());
    ...
  }
// ...
};
Any code calling DoPush should have already claimed the semaphore before
calling DoPush().  That is the ONLY reason I have for it.  I do NOT have a
"who owns it?" function.  If you want to know if someone else has it, try to
claim with a 0 timeout... but it doesn't tell who.
... Drop your carrier ... we have you surrounded!
--- FastEcho 1.46
---------------
* Origin: House of Fire BBS - Toronto - (416)601-0085 - v.34 (1:250/536)

SOURCE: echomail via exec-pc

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™.