Quote:Original post by toro
I do know the mechanism, however I didn't know that it is called guards... my question is if it is common to C++ implementations or there is any reason why I should avoid it?
Not at all. It's the right thing to do.
(OPS: plus pluses are getting chopped)Your ckernel object is responsible for running tasks and killing tasks. In main (probably) instantiate your ckernel, then your tasks. Then add your tasks one by one. Right now you're prioritizing by chronological order (higher priority tasks are added first). If you store your tasks in a vector or list, it's much easier to define priority when adding tasks. In addition, killing, re-prioritizing or suspending tasks are made much simpler, since re-ordering is done for you by the STL. The set of articles I linked to explain this (task prioritization and killing) in great detail, although if you're not familiar with smart pointers, you may want to research those.
Quote: ctask *pctask[21]; int task_count;
You're coding in C plus plus now, time to drop those unsafe, pain in the butt C arrays[smile]. Also, you're limiting your task count - why?
Quote:void ckernel::Run() { for (int i=0; i<task_count;i++) { pctask->DoSomething(); } }
Here you're iterating through your task array, and executing them all. Then what? What if a task wants to die? What if there are no more tasks? Currently you have no support for killing tasks without alot of hassle - this is why you use a std::list. Instead of having seperate functions in your kernel, you can do all of this in this function.
As long as you have living tasks, iterate through your task list, and DoSomething() to all tasks that are not ready to die. Iterate again and remove those tasks that are (if you're using smart pointers this effectively destroys the task for you).
So, ckernel::Run executes until there are no more tasks. (What else would you want to do inbetween your task loop? Remember, your tasks are the objects that make up your system, the kernel just sees that they get executed.)
style-wise, I can read your code well. And if you have nobody else that's looking at your code, (or going to be looking at it) then all that matters is if you can read it. I do the following:
class SomeClass { int some_int_; int * psome_int_;public: SomeClass( int some_var ): some_int_(some_var), psome_int_( new int( some_int_ )) {}; ~SomeClass() { delete psome_int_; };};
:stylin: "Make games, not war.""...if you're doing this to learn then just study a modern C++ compiler's implementation." -snk_kid