Skip to content

Commit c5fedba

Browse files
committed
Merge pull request #894 from dotty-staging/check-singlethreaded
Check that access to context base is singlethreaded.
2 parents cdfcbc1 + 5b2d94a commit c5fedba

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/dotty/tools/dotc/Run.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Run(comp: Compiler)(implicit ctx: Context) {
5050
}
5151

5252
protected def compileUnits() = Stats.monitorHeartBeat {
53+
ctx.checkSingleThreaded()
5354
val phases = ctx.squashPhases(ctx.phasePlan,
5455
ctx.settings.Yskip.value, ctx.settings.YstopBefore.value, ctx.settings.YstopAfter.value, ctx.settings.Ycheck.value)
5556
ctx.usePhases(phases)

src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,16 @@ object Contexts {
611611
superIdOfClass.clear()
612612
lastSuperId = -1
613613
}
614+
615+
// Test that access is single threaded
616+
617+
/** The thread on which `checkSingleThreaded was invoked last */
618+
@sharable private var thread: Thread = null
619+
620+
/** Check that we are on the same thread as before */
621+
def checkSingleThreaded() =
622+
if (thread == null) thread = Thread.currentThread()
623+
else assert(thread == Thread.currentThread(), "illegal multithreaded access to ContextBase")
614624
}
615625

616626
object Context {

0 commit comments

Comments
 (0)