Re: C++ in kernel (was Re: exception in a device driver)
Chip Salzenberg (chip@perlsupport.com)
Sat, 16 Jan 1999 00:11:19 -0500
According to Oliver Xymoron:
> On Mon, 11 Jan 1999, Chip Salzenberg wrote:
> > In C the kernel says e.g. 'return -ENOENT'. That's not 'handling'
> > the error at all! It's just *reporting* the error.
> >
> > Replace the 'return' with a 'throw' in C++, and nothing's different,
> > except that it's effectively a multi-stack-frame return that's used
> > to _report_ errors.
>
> Not anywhere near that simple. Having exceptions anywhere in the kernel
> would require protecting basically every critical section with exception
> handling (much worse than the current small number of spinlocks) to avoid
> leaving data/hardware/spinlocks in an inconsistent state ...
You're working too hard (or at least proposing that someone _else_
work too hard). Just follow Stroupstrup's design rule: "Constructors
acquite resources; destructors release them."
Because destructors are automatically called as stacks unwind.
Think auto_ptr<>.
> Exceptions are not your friend.
Well, maybe they're not *your* friend... :-)
--
Chip Salzenberg - a.k.a. - <chip@perlsupport.com>
"When do you work?" "Whenever I'm not busy."
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/