Live data from Hacker News

How to Make a Computer Operating System in C/C++

github.com

31–40 of 88 posts

Re: How to Make a Computer Operating System in C/C++

#31

Who remembers Nachos? https://en.wikipedia.org/wiki/Not_Another_Completely_Heurist... 3rd year OS class we had to use Nachos as our base OS and build your usual file management, pipes etc. functionality on top of it. Really taught you how an OS works.

Our school used Pintos, a derivative of Nachos. Taking the OS course there was an eye-opener for a student as technically immature and inexperienced as I was at that time, but it was also a tremendous learning experience. I've always wished I could go back and retake that course, the 'right way'...with these resources, though, maybe there's a better way.

Re: How to Make a Computer Operating System in C/C++

#32
post #26
post #25

Earlier quoted context omitted.

You can have generalized containers in C, using the intrusive pattern. For example, Linux's list.h has an intrusive list that is far better than the abysmal std::list from the STL.

Any C++ programmer knows not to use std::list anyway.

How about: Any C or C++ programmer knows not to use linked lists anyway.

Re: How to Make a Computer Operating System in C/C++

#33
post #25

Earlier quoted context omitted.

You can have generalized containers in C, using the intrusive pattern. For example, Linux's list.h has an intrusive list that is far better than the abysmal std::list from the STL.

I've only recently started C++ development...why is std::list abysmal?

I found a stack overflow question that seems to go over it. Basically it looks like there's almost always a better choice for whatever you're doing.

http://stackoverflow.com/questions/18449038/is-there-ever-a-...

Re: How to Make a Computer Operating System in C/C++

#34
post #26

Earlier quoted context omitted.

Any C++ programmer knows not to use std::list anyway.

How about: Any C or C++ programmer knows not to use linked lists anyway.

If you really think that, you've missed CS 101. Or maybe std::list is the only linked list implementation you've seen. In that case, I agree, one should never use std::list.

Linux's list.h is extremely useful, and for a wide variety of circumstances, is the most efficient way to manage your data.

Re: How to Make a Computer Operating System in C/C++

#35
Might also be worth looking at xv6, which is a rewrite of Unix v6 in modern C, and comes with an exegesis modelled on the classic Lions book:

http://pdos.csail.mit.edu/6.828/2012/xv6.html

(Although if you want to run the original Unix v6, written in a now-archaic proto-C --- unsigned integer variables are declared as pointers because "unsigned" itself wasn't directly supported in the language yet --- PDP-11 emulators and system images are readily available.)

Re: How to Make a Computer Operating System in C/C++

#36
post #26
post #25

Earlier quoted context omitted.

You can have generalized containers in C, using the intrusive pattern. For example, Linux's list.h has an intrusive list that is far better than the abysmal std::list from the STL.

Any C++ programmer knows not to use std::list anyway.

The rest of the data structures in the STL follow the same (anti-)pattern.

They all either take ownership of your data, or point at your data unidirectionally.

This means that given a pointer to your data you cannot, for example, delete it from multiple data structures it is contained within without going from these structures roots to re-find the pointers to your data.

Whereas with intrusive data structures (the way it is done in the Linux kernel and other "advanced" C projects), you can easily embed your structure in multiple data structures, such that you can do very quick deletion or modification of the data without re-finding it.

Re: How to Make a Computer Operating System in C/C++

#37

Earlier quoted context omitted.

I've only recently started C++ development...why is std::list abysmal?

I found a stack overflow question that seems to go over it. Basically it looks like there's almost always a better choice for whatever you're doing. http://stackoverflow.com/questions/18449038/is-there-ever-a-...

That answer is attributing the badness to linked lists, whereas it is fully std::list's. Linked lists are very useful, but it's hard to see that when their canonical (and almost only) implementation is std::list, which is indeed almost entirely useless.

Re: How to Make a Computer Operating System in C/C++

#38
post #25

Earlier quoted context omitted.

> write a very simple UNIX-based operating system in C++ (does anyone else smell a contradiction?) I'm going to use this as an opportunity to champion C++ for systems programming despite the fact that it wasn't really your argument. I feel obligated to do this because I agreed with you for a long time on this but have changed my mind over the past year or two. The argument against C++ as a systems programming languag…

You can have generalized containers in C, using the intrusive pattern. For example, Linux's list.h has an intrusive list that is far better than the abysmal std::list from the STL.

Intrusive datastructures were the thing I missed most from C, but boost::intrusive satisfies my desires when it's absolutely necessary.

In general, I'm anti-boost, but I think it's a personal bias and we use the hell out of it at work to great effect. The one thing I'll give boost::intrusive over sys/queue.h is that the type system helps you a lot more to catch issues and the common case is a bit simpler (a struct that exists in a single linked list and a single hash table, for example).

I've been burned many times by something like the following

  struct foo {
    TAILQ_ENTRY(foo) lru_entry;
    TAILQ_ENTRY(foo) hash_entry;
  };
  ...
  void some_magic_func(struct foo *f) {
    TAILQ_REMOVE(static_tailq, f, hash_entry); // oops, should be lru_entry!
  }
Boost intrusive templatizes on the member as well (IIRC) and eliminates this whole class of problem.

Re: How to Make a Computer Operating System in C/C++

#39
post #25

Earlier quoted context omitted.

You can have generalized containers in C, using the intrusive pattern. For example, Linux's list.h has an intrusive list that is far better than the abysmal std::list from the STL.

Intrusive datastructures were the thing I missed most from C, but boost::intrusive satisfies my desires when it's absolutely necessary. In general, I'm anti-boost, but I think it's a personal bias and we use the hell out of it at work to great effect. The one thing I'll give boost::intrusive over sys/queue.h is that the type system helps you a lot more to catch issues and the common case is a bit simpler (a struct th…

In C, you can use a bit of macro trickery to get the same safety, e.g: by defining a 0-sized array of the some type alongside the intrusive node. Then, macros that do the "cast down" from the intrusive node to the container element can also do a type-comparison (using some trickery) between the anchor's array and the container type.

I've seen it implemented, but everyone uses the typical non-type-safe one anyway :)

I don't think I've ever had such bugs in a lot of code though, since I tend to wrap the "containerof" call with a little function like: foo_of_lru_entry and foo_of_hash_entry. A bit of boilerplate for each data structure, but worth it.

Re: How to Make a Computer Operating System in C/C++

#40
Maybe a little irationally, the idea of programming an os in c++ strikes me as very opaque. I think the vipri[1] approach of layering dsls, or the smalltalk idea of a relatively simple vm to seem more understandable than an os that embeds a c++ runtime...

As a side note, when looking up [1] I also ran across [2].

[1] http://piumarta.com/software/cola/ [2] http://www.acm.uiuc.edu/sigops/roll_your_own/1.helloworld.ht...

Post reply on HN