Hacker News new | past | comments | ask | show | jobs | submit login

Really? Go take a look at the two code snippets in "The Reentrant Kernel." I can't tell what the salient difference is supposed to be between them, much less how they are meant to illustrate the concept of reentrancy.

I mean, I appreciate the concept of what she's doing here, but that self-assessment sounds reasonable to me.




I appreciate any feedback, of course, I'm trying to learn here! About the snippets you mentioned, my reasoning was:

There's a variable outside of the functions scope. If the value of the global variable were changed before it's referenced in the function the outcome would change.

  int global_int;
  int is_not_reentrant(int x) { 
    int x = x; // An arbitrary operation
    return global_int + x; // the result depends on global_int
  }
In the second, the value of the global_int is copied into a variable within the function; so the result is no longer dependent on anything outside of the function's scope. My thinking was, that this demonstrated reentrancy.

  int global_int;
  int is_reentrant(int x) { 
    int saved = global_int; 
    return saved + x;
  }
From the looks of it I did make a mistake, since it seems to be missing one of these criteria. I'll modify the snippets to fix it. Thanks! :)

  +Must hold no static (or global) non-constant data.
  +Must not return the address to static (or global) non-    constant data.
  -Must work only on the data provided to it by the caller.
  +Must not rely on locks to singleton resources.
  +Must not modify its own code (unless executing in its own unique thread storage)
  +Must not call non-reentrant computer programs or routines.


Yeah, I would argue that both of those functions are re-entrant. The question is whether you can have two calls to is_not_reentrant executing concurrently without interfering with each other. So a typical example would have a non-reentrant function altering a variable like global_int as part of its computation.

Also, it's important to think about the kinds of program transformations that the C compiler is free to do with your code when going from C to assembly. I think it's likely that your compiler would produce the same output for both functions. Lines of C code do not execute atomically, and instructions can be re-ordered.

EDIT: Returning to this because I think I made a mistake. "Two calls executing concurrently" is not exactly right, because it admits the possibility of arbitrary instruction interleaving. A reentrant function must be able to be paused at any point, have another call to the function execute entirely, and then resume correctly. This is a weaker condition.


> I mean, I appreciate the concept of what she's doing here, but that self-assessment sounds reasonable to me.

I would use "realistic", as opposed to "reasonable", look hard enough and you will see that everyone has gaps in their knowledge.


That's a vacuous statement. She said "big" gaps. And I'm saying that she's making errors that no one with a background in CS (e.g. a degree) ought to make.

I have no idea what your agenda is in lavishing all this unnecessary praise on Morgan Phillips, but it's gross. Please stop.


> That's a vacuous statement. She said "big" gaps. And I'm saying that she's making errors that no one with a background in CS (e.g. a degree) ought to make. I have no idea what your agenda is in lavishing all this unnecessary praise on Morgan Phillips, but it's gross. Please stop.

Is your name Linus Torvalds by any chance?


I don't have any desire to be lavished in praise; but you're being unnecessarily rude I think. :[


Hey, I picked this username for a reason.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: