Search code examples
javascalaconcurrencycompilationreentrancy

Reentrancy and static data in an early implementation of the Scala compiler in Martin Odersky's talk. How are they related?


In Martin Odersky's talk :http://youtu.be/9PkxE_L_LMo , at 49. minute he talks about a problem that "the compiler is not re-entrant" because of static data.

I have a basic understaning about what the term "reentrancy" means in Java (for example, if I invoke a synchronized method recursively then I won't get into a deadlock) , but I still don't understand what Martin is talking about.

Why is it not possible to run two compilers in the same JVM if the code is written as shown at 49th minute of the talk?

What kind of reentrancy is he talking about?

I assume when he refers to reentrancy in the 49. minute of his talk, he does not mean the kind of reentrancy that allows one to use recursive synchronized method invocations in Java without getting into deadlock. Am I right? I am not sure.

Is he simply refering to the fact that when on has mutable static data accessed from several threads then the program will work incorrectly due to race conditions?

Please enlighten me!


Solution

  • What kind of reentrancy is he talking about?

    He's talking about the one computer science definition for re-entrant. Besides the wikipedia article, this IBM developerWorks article states it clearly:

    A reentrant function is one that can be used by more than one task concurrently without fear of data corruption. Conversely, a non-reentrant function is one that cannot be shared by more than one task unless mutual exclusion to the function is ensured either by using a semaphore or by disabling interrupts during critical sections of code. A reentrant function can be interrupted at any time and resumed at a later time without loss of data. Reentrant functions either use local variables or protect their data when global variables are used.

    Being that static variables are the object-oriented version of global variables, Odersky is talking about a compiler that doesn't protect its global variables.

    Is he simply refering to the fact that when on [sic] has mutable static data accessed from several threads then the program will work incorrectly due to race conditions?

    Essentially, yes. The compiler may not function correctly when invoked concurrently because it would mix information about multiple programs, resulting in possible corruption.