-=> Quoting Thomas Maeder to Darin McBride
DM> the STL. Except that it doesn't really want to work if I make it vo
DM> If it is volatile, the compiler complains. If it isn't volatile, it
TM> How do you make it volatile, and how does the compiler complain?
#include // for queue
#include
class Comm
{
// my member variables are actually at the bottom, but we'll show 'em
// here. Assume that queue is mutex'ed on everything.
typedef queue > IOQueue;
// the read & write queues. Can be modified on other threads by friends.
volatile IOQueue m_ioqRead;
volatile IOQueue m_ioqWrite;
public:
void Write(char c);
// plus others
};
void Comm::Write(char c)
{
m_ioqWrite.push(c); // !!!
}
On the marked line (!!!), the compiler complains that it cannot find a
function "queue >::push(char) volatile". The function, without
volatile, exists, though.
I've switched to a circular queue that is hand-coded rather than an STL-based
queue, and have it working now. But, I'd rather have an STL-based queue ...
because then I'd have working code that would give me practically limitless
queues - then I could still limit them, but I could change the limits on the
fly instead of hard-coding a 4K write buffer and a 32K read buffer. (My
circular queue can be told, at construction time, what size to use, but would
be rather difficult to maintain if it could change its size at any time.)
At least this one is template-based. I can always change the type later to
include "command" objects. That will come in useful. :-]
I'd post it, but the hand-coded queue uses OS/2 mutex's. Mind you, if I
posted the entire class hiearchy, anyone who wanted to convert the one mutex
class to Win32 could, and the rest of the class would work just fine. :-) A
semaphore, in this class hiearchy, needs to:
Create (publically, based on a semaphore name - not used by my queues)
Create (privately, without a semaphore name)
Claim (optionally with a timeout to wait for the semaphore to become
available)
Release
Close
Tell if the current thread has it claimed (note that the same object can
be used by multiple threads in the same process)
Tell if the semaphore name (in the public create) is valid
If this is possible in Win32, I can post what I have for OS/2... :-)
... Documentation - The worst part of programming.
--- FastEcho 1.46
---------------
* Origin: House of Fire BBS - Toronto - (416)601-0085 - v.34 (1:250/536)
|