Reschedule processes when they can not obtain the mailbox lock in time
When a process sends a message to another process that is garbage collected, the sending process (and corresponding OS thread) may be blocked when trying to acquire the mailbox lock. We should reschedule the sending process if it's unable to acquire the lock in a reasonable time.
The use of a fixed number of OS threads means that blocking operations have a performance impact. If a receiving process has a very large heap, the sending process/thread may be blocked for an extended period of time. By rescheduling the sending process we can reduce this to a minimum.
Mutex type provided by parking_lot has
a method "try_lock_for", which can be used to try to lock a Mutex with a timeout. Since rescheduling is
not free, just using
try_lock may result in a process being rescheduled prematurely. Using
we can prevent this by using a reasonable timeout (e.g. 100 microseconds).
These changes may complicate sending process messages a little bit, though it should not be that big of a deal.