Tech Off Post

Single Post Permalink

View Thread: IL to C++ compiler - Need advice on implementing context switching
  • User profile image

    Hmm, there's one problem I forgot to mention. In addition to stack and static variables there's one more place where you need to look for references: CPU registers.

    This seems to be rather complicated to solve even in the absence of multithreading due to the fact that you generate C++ code, not assembly. Imagine this:

    void SomeMethod() {
    foo bar = new foo();

    Let's say that new runs out of memory and triggers a GC. Let's also say that there's no threading and that the GC happens on the same thread. Even in this simple case you have no idea what the CPU registers contain when the GC code is entered, it's up to the compiler.

    As for threading: I'm not familiar with these microcontrollers but I'm not sure why you would need all that machinery. As long as the CPU supports interrupts you should be able to implement preemptive multithreading without the need for this Pending/Switch stuff. And if the CPU doesn't have interrupts then who is going to set Pending anyway? You may need some form of cooperative multithreading in that case.