Racket class and thread interplay
<p>This question is not about a particular problem I am having, but rather something I find difficult to wrap my head around. The context of the problem is racket classes and threads. Consider the following <code>actor%</code> class which contains an actor thread, a method to queue a message in the mailbox of the thread, and a method to receive a return value (it does nothing useful and only prints it). </p>

<pre><code>(struct message (source method values))

(define actor%
  (class object%
    (super-new)

    (init-field
     [actor-thread 
      (create-actor-thread this)])

    (define/public (receive-message source method arguments)
      (define message (message source method arguments))
      (thread-send actor-thread message))

    (define/public (receive-value value)
      (displayln value))))
</code></pre>

<p>As a side-note, if one wanted to create an actor, they would have to first create a subclass that implements certain messages (as methods) that the actor understands. They have a mechanism to send a message (e.g. <code>(actor-send actor 'hello 'world)</code> for sending a message to actor <code>actor</code> that invokes method <code>hello</code> with argument <code>world</code>).</p>

<p>All actors run within their own thread, which is defined as follows. In short: it takes a message from the inbox of a thread, it gets the source (an actor), the method (a symbol), and some values (a list), and <a href="https://docs.racket-lang.org/reference/ivaraccess.html?q=dynamic%20send#%28def._%28%28lib._racket%2Fprivate%2Fclass-internal..rkt%29._dynamic-send%29%29" rel="nofollow">dynamically sends</a> it to himself to invoke the appropriate method on the instantiated subclass of <code>actor%</code>. </p>

<pre><code>(define (create-actor-thread self)
  (thread
   (lambda ()
     (let actor-loop ()
       ;#####----- Receive message -----#####
       (define message       (thread-receive))

       (define source       (message-source message))
       (define method       (message-method message))
       (define values       (message-values message))
       (define return-value (dynamic-send self method values))

       (send source receive-value return-value)
       (actor-loop)))))
</code></pre>

<p>I know for a fact that the body of the invoked message is processed in the context of the new thread, but how does this work from a concurrency perspective for the actor? Meanwhile, while the actor thread is doing heavy work, the actor can keep queuing messages in the thread's mailbox. The thing I cannot wrap my head around (or can find a reasonable explanation for) is that the actor object seems to live in two contexts: the original context, and the context of the actor thread. Both can access the same object. Is there a false sense of concurrency, or is there some magic making this all work nicely? </p>