Lets say I have a class where each object should interact independently. For example, I may have various tables out of a database over many servers offsite. However, internally, I happen to know that some of the tables are linked, and I can save a significant amount of IO by grouping commands that do not require any response together. My goal is to be able to write code using the interface for Table as such:
void bar() {
// queue time is 500 milliseconds
Table::queue_time = 500;
Table a("foo"),b("baz"),c("cat");
// Call some function for members of this class
a.add(2);
b.add(5);
// Command is sent to database
sleep(1);
// This command will be sent later
c.add(5);
}
I want this code, in effect, to actually only send two commands to the database. After first calling a.add(), I want a sort of "queue" to begin that after 500ms will issue a command to the database. When b.add() is called, I would like this new instruction to be tossed onto this queue. However, since the sleep happens (and time passes enough for the instruction to send away), I would like c.send() to actually begin a new queue which will send, again, within 500ms.
The trick, however, is that I'd like to do this without threads if possible. Is it even possible (I'm inclined to think not)? If not, what tools in C++ are fit for the job, and how can I communicate with objects that will be edited before being read from while that thread is sleeping?
(In reality, this has nothing to do with databases, so don't worry about the fact that this would be useless for them)