base: test for races in thread-context allocation

Related to #1024.