[openbeos] Re: C++ in the kernel

  • From: "Axel Dörfler" <axeld@xxxxxxxxxxxxxxxx>
  • To: openbeos@xxxxxxxxxxxxx
  • Date: Sun, 23 Feb 2003 19:37:42 +0100 CET

"Michael Phipps" <mphipps1@xxxxxxxxxxxxxxxx> wrote:
> Exceptions (in C++) are not a really good paradigm for kernel work 
> anyway, unless you have a completely C++ kernel. Why, you may ask? 
Well, let me share an experience from VM2. 
> I am using exceptions in VM2, WHILE IT IS IN USER LAND, to emulate 
> signal handling. 
> I recently ran into a situation where the whole VM hung with no 
> explanation. It turned out that I had a semaphore locked and threw an 
exception. When another thread tried to run, it was completely blocked.
> 
> The solution is one of:
> 1) A "finally" clause, like in Java, where no matter what code path 
> occurs, exception or not, certain things happen.
> 2) A constructed class (like a BAutoLocker) that will go out of scope 
> when the exception occurs
> 3) Don't use exceptions
> 4) Replicate all of the "normal exit" code before throwing.
> 
> 1 isn't an option. 2 could be done. 3 was my final choice and 4 was 
> my interim solution.

Yes, I agree, 3) does fine for me :-)

> >Virtuals are possible - just RTTI needs some bits from the C++ link 
> >library that you would have to implement yourself. Of course, that 
> >would make the kernel dependent on a specific compiler version which 
> > we 
> >want to avoid for the time being.
> Yes. Also the performance issues. 

There is no real performance issue - for most compilers (incl. gcc) 
it's just a matter of dereferencing a pointer (and compare that value 
to another :).

> >> - STL: not sure why
> >Only because it uses features that need aren't provided in the 
> > kernel C
> >++ runtime library. But it's possible to find your way around it, as 
> >outlined above.
> STL has potential to be a performance issue. This is not a criticism 
> of it, as such,
> but STL makes it very easy to do bad (slow) things. It also makes 
> doing good
> things easier. 

Yes, I would also not recommend to use the STL in the kernel (too much 
of a big thing ;-)).

> Templates. Hmph. :-)

Templates are a great way to overcome the OO limitations of C++ :-)

Adios...
   Axel.



Other related posts: