this post reveals implementation details for os and 213 assignments. if you will take these classes in the future, then academic integrity implores you to read no further.
a lot of times when trying to solve a problem you'll find yourself shooting for something without actually evaluating whether you're on the right track at all. the appropriate question here is, "is it necessary and sufficient?" let's see a few examples:
- in os p0, one of the most frequently asked questions is, "should i stop printing functions when i find main()?" well, this is not quite sufficient, because a stack trace may not have a main function at all, and you will need to look for a different terminal condition. but it is also not necessary, because any end-case-detection that will work in the no-main() case will also work in every other case. all that implementing main()-detection buys you is a little bit of prettiness in the typical traceback.
- when TAing 213, a student asked me one time in recitation if for proxylab it would be a better idea to just spawn threads as requests were received, or to create a pool of worker threads at initialization for handling requests later. i didn't know offhand, so i took the approach i didn't already know to be correct (the latter one), and asked this question of it. it is not sufficient, because - supposing you have a pool of N threads - N+1 simultaneous requests will mandate extra code for spawning threads as requests are received. it is also not necessary, because as long as you have the code to do so, you may as well use it to solve the general-case problem as well. however, it does buy you something: in the general case, you save on the cost of spawning and exiting a new thread for each request.
- (the obligatory non-coding case.) when you have a crush on someone, it's easy to be miserable and think "o, would all my problems be solved if only they would fall into my arms!" here we go again: it's not sufficient, because in theory you should be able to stand upright on your own without depending on any romantic involvement, and it's not necessary, because if you are as healthy as just mentioned, you won't need anybody to fall into your arms in order for you to be happy. and of course, assuming you are already healthy, being "successful" here will facilitate general contentment, so to speak.
so that's the difference between two kinds of proposed solutions: the first one you're likely to come up with is not a correct solution - there will be something, likely more hidden, that will solve the actual problem - but it can be implemented on top of something that is correct because it gives desirable results. (who wants to see a backtrace that prints __libc_start_main all the time anyway?)