Live data from Hacker News

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

github.com

71–80 of 88 posts

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

#71
post #58

Earlier quoted context omitted.

Not at all!

Could you provide some pointers? I'm kinda in the same situation.

You really need an EE or CompSci degree these days. That's the first point of call.

I don't have either but it was a little different when I started. I managed to build a reputation up on the side and go from there. Eventually people stop asking about qualifications.

EE is probably more important than a comp sci education for embedded work. Its a fairly complicated field which deals with things far below the abstraction of a machine.

If anyone mentions the word Arduino though, stop listening there and find someone else. They're assumed to be like the real world but are faaaar from it.

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

#73
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…

You might find http://www.locklessinc.com/articles/dlist/ interesting: it describes a (perhaps excessively) clever way to do intrusive lists that gives type checking.

(Unfortunately it does rely on `typeof`, an extension.)

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

#74
post #72

How about making a language, compiler, OS and applications and not use C or C++ ? https://news.ycombinator.com/item?id=6829464

You forgot to add in your list: making a completely new processor ;) Which the linked project actually achieves.

There's that too. Although I'd like to have the time to port Oberon to MIPS, maybe the PIC32 since the more powerful, modern MIPS chips are out of budget. Haven't done the analysis, but I think it would be a good match.

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

#75
post #71

Earlier quoted context omitted.

Could you provide some pointers? I'm kinda in the same situation.

You really need an EE or CompSci degree these days. That's the first point of call. I don't have either but it was a little different when I started. I managed to build a reputation up on the side and go from there. Eventually people stop asking about qualifications. EE is probably more important than a comp sci education for embedded work. Its a fairly complicated field which deals with things far below the abstract…

I think that was pretty bad advice. If someone wants to start doing embedded you tell them to go get a CompSci degree (i.e. studying algorithms and logic).

And disrespecting Arduino like that does not seem good either. Doing Arduino will actually teach you about both microcontrollers and electronics and there's a lot of nice modules available. Of course it is not like writing your own OS but it's a start, and you can always use the hardware and ignore the Arduino software.

The best way to get started in embedded is to begin on a project where you actually build something that you want to build. That will help you with requirements on the platform you choose, be it Arduino, Raspberry Pi, FPGA or whatever.

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

#76
post #34

Earlier quoted context omitted.

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.

Ok, I'll elaborate, especially since my view is at odds with your statement "for a wide variety of circumstances" . As I see it, the only use case where linked lists are superior to other types of lists, like, perhaps, ArrayList in java or vector/deque in C++, is if the following conditions are met: 1: you care about ordering - often you don't care about ordering and in that case, there is no need for a linked list b…

To further prove the point about cache locality:

https://www.youtube.com/watch?v=0iWb_qi2-uI&t=44m50s

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

#77
post #71

Earlier quoted context omitted.

You really need an EE or CompSci degree these days. That's the first point of call. I don't have either but it was a little different when I started. I managed to build a reputation up on the side and go from there. Eventually people stop asking about qualifications. EE is probably more important than a comp sci education for embedded work. Its a fairly complicated field which deals with things far below the abstract…

I think that was pretty bad advice. If someone wants to start doing embedded you tell them to go get a CompSci degree (i.e. studying algorithms and logic). And disrespecting Arduino like that does not seem good either. Doing Arduino will actually teach you about both microcontrollers and electronics and there's a lot of nice modules available. Of course it is not like writing your own OS but it's a start, and you can…

I disagree. CompSci is mainly userland.

Most EE courses these days have the majority of a comp sci course built in. MIT actually blur the line between both. Pure comp sci will not help you understand why your RS485 bus drops have noise, why your serial wont sync and how to get stuff off an SPI bus by bit banging. It's all analogue at the bottom of the stack as well which is why embedded systems people still have scopes on their benches.

Comp sci only people shit a brick when you lug the scope onto the bench and crack out the probes.

The Arduino teaches you to do so many things wrong that its almost dangerous and requires a lot of unlearning. Build an AVR programmer and use gcc fine but lose all the arduino crap over the top and gain JTAG debugging, single step, more memory (!), full IRQ control, timers etc that aren't under a layer of crud. Oh an ISR that runs in under an hour as well, CMT. I could go on for a week.

For ref, you won't find a job writing software for or using an Arduino or a Pi either. FPGA yes, ARM SoC yes, AVR maybe, PIC maybe, x86/PC104 yes.

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

#78
post #34

Earlier quoted context omitted.

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.

Ok, I'll elaborate, especially since my view is at odds with your statement "for a wide variety of circumstances" . As I see it, the only use case where linked lists are superior to other types of lists, like, perhaps, ArrayList in java or vector/deque in C++, is if the following conditions are met: 1: you care about ordering - often you don't care about ordering and in that case, there is no need for a linked list b…

> 1: you care about ordering - often you don't care about ordering and in that case, there is no need for a linked list because you can achieve O(1) insertion & removal then too: insertion can always be at the end, removal can be a "swap with end element, remove end element" operation.

Whether you care about ordering or not, linked lists work great. Adding to an array is only amortized O(1). It is worst-case O(N). Why pay O(N) for the worst case when you can pay a cheap O(1) always?

> 2: inserting and/or removing from the middle of the list is a common operation, if it is not a common operation, then the added cost of doing so with a vector may still be outweighed by a vectors other advantages

Deleting from the middle of the list is an extremely common requirement, when you have objects that need to be enumerable in some order[s] and sometimes deleted.

> 3: you do not require random access - lists do not provide random access and lookup is O(n). At the expense of additional complexity in implementation and more memory overhead, you could reduce lookup to, OTOH, O(log n) by using a skip-list

Here is a false dichotomy dictated by the STL. With intrusive lists, you can have both your vector and lists of various orders. There is no contradiction.

When you need indexing, use a vector. When you need quick add/remove, use lists. When you need both, use both.

> 4: you do not iterate through the list often - if you do, you are likely going to blow the cache and mess up prefetching due to poor cache locality. Iterating through an array-based data structure can be much faster in this case.

Yes, if you want quick (repeated) enumeration, put it in a vector. Again, this doesn't contradict also putting it in lists.

> The biggest issue they seemed to mention, though, was cache locality - I fail to see how intrusive linked lists solve this.

Cache locality is based on your use pattern. When enumeration isn't your common operation, vectors don't have better locality than lists. For example, a sorted list of requests where you may want to time out the oldest one will only refer to the head and tail of the whole list. Cache locality is great.

> then you end up jumping around the preallocated nodes anyway and after a while will lose any cache-friendliness you may have had.

You don't need to jump around. Say you have a request object you found via a hash table. After handling it you decide to destroy it. You now want to delete it from various lists it is in. You can do it on all lists in O(1) for each list. This is relatively cache-local (only need 2 extra random accesses, potential misses, for each list).

> C programmers are trained to use linked lists. They are the first variable-length containers most programmers come into contact with and so C programmers tend to be imprinted on them like ducklings. Linked lists are a poor general purpose container.

I think the false premise here, espoused by the STL, is that a data structure is a "container" at all. Your data can be "contained" by anything (the stack, the heap, a vector, ...). The data structures involved (linked lists, hash tables, search trees) all do not contain the data. They organize the data.

When using vectors as containers STL-style -- you cannot really have your data organized by multiple data structures efficiently.

I regularly have my data objects within a hash table, a list, and a search tree simultaneously and efficiently, with no dynamic allocation to sustain any of that.

STL cannot do this because of the data-structure as "container" philosophy.

EDIT: Also read my other comment detailing why std::list is lacking the most fundamental properties expected of a linked list: https://news.ycombinator.com/item?id=6830526

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

#79
post #76

Earlier quoted context omitted.

Ok, I'll elaborate, especially since my view is at odds with your statement "for a wide variety of circumstances" . As I see it, the only use case where linked lists are superior to other types of lists, like, perhaps, ArrayList in java or vector/deque in C++, is if the following conditions are met: 1: you care about ordering - often you don't care about ordering and in that case, there is no need for a linked list b…

To further prove the point about cache locality: https://www.youtube.com/watch?v=0iWb_qi2-uI&t=44m50s

This is a strawman. This isn't a useful case for lists.

Since he needs to scan the list to find the position to add/remove to/from.

If he used an intrusive list, the removal from a vector-with-list would be faster in a list already for relatively small N's.

What I learn from this video is that Stroustroup is also misguided about linked lists. He thinks you always need to do a linear search to do useful operations. The whole point of lists is the O(1) operations, not O(N) operations.

Indeed, std::list is the culprit here: "We shape our tools and then our tools shape us". std::list users become unaware that list operations are usable on elements without a linear search first.

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

#80
post #54

Earlier quoted context omitted.

please tell me it was some kind of joke

Possibly but I think it's real. I believe it's the same guy from this: http://i.imgur.com/evPQL2S.jpg

Found that guy's facebook. It does seem real, I mean the person seems real, but I still really hope they're doing this as a joke or something.
Post reply on HN