Use CriticalSection to prevent deadlocks on dequeue

@millerdev yeah, that's supposed to be the case, but there have been reports of deadlocks when dequeuing, so I want to see if this fixes it