diff options
author | Martin Odersky <odersky@gmail.com> | 2015-10-31 09:57:50 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-10-31 09:57:50 +0100 |
commit | 5b2d94a274abe82d26687f1c6ef19fb1d57df2dd (patch) | |
tree | fc841753cc74d630814e10e4d8f51bc28f275f4b /src | |
parent | ac347485e94061d548bebc794ee133bb1b248a48 (diff) | |
download | dotty-5b2d94a274abe82d26687f1c6ef19fb1d57df2dd.tar.gz dotty-5b2d94a274abe82d26687f1c6ef19fb1d57df2dd.tar.bz2 dotty-5b2d94a274abe82d26687f1c6ef19fb1d57df2dd.zip |
Check that access to context base is singlethreaded.
ContextBase is not intended to be threadsafe, We now test that
indeed it is not shared by compileUnits calls operating on
different threads.
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/Run.scala | 1 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Contexts.scala | 10 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/Run.scala b/src/dotty/tools/dotc/Run.scala index 114f994be..ba86e3e70 100644 --- a/src/dotty/tools/dotc/Run.scala +++ b/src/dotty/tools/dotc/Run.scala @@ -50,6 +50,7 @@ class Run(comp: Compiler)(implicit ctx: Context) { } protected def compileUnits() = Stats.monitorHeartBeat { + ctx.checkSingleThreaded() val phases = ctx.squashPhases(ctx.phasePlan, ctx.settings.Yskip.value, ctx.settings.YstopBefore.value, ctx.settings.YstopAfter.value, ctx.settings.Ycheck.value) ctx.usePhases(phases) diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala index f9d64b2cc..d5fdba1af 100644 --- a/src/dotty/tools/dotc/core/Contexts.scala +++ b/src/dotty/tools/dotc/core/Contexts.scala @@ -611,6 +611,16 @@ object Contexts { superIdOfClass.clear() lastSuperId = -1 } + + // Test that access is single threaded + + /** The thread on which `checkSingleThreaded was invoked last */ + @sharable private var thread: Thread = null + + /** Check that we are on the same thread as before */ + def checkSingleThreaded() = + if (thread == null) thread = Thread.currentThread() + else assert(thread == Thread.currentThread(), "illegal multithreaded access to ContextBase") } object Context { |