Serving multiple HTTP requests to a store simultaneously when the «var/generation» folder is empty leads to a random shared resources access (concurrency) conflict

The failure message is random, for example:

Can't create directory C:/work/mage2.pro/store/var/generation/Magento/Framework/App/Cache/Type/Config/.
#0 lib\internal\Magento\Framework\Code\Generator\Autoloader.php(35): Magento\Framework\Code\Generator->generateClass('Magento\\Framewo...')
#1 [internal function]: Magento\Framework\Code\Generator\Autoloader->load('Magento\\Framewo...')
#2 [internal function]: spl_autoload_call('Magento\\Framewo...')
#3 lib\internal\Magento\Framework\ObjectManager\Relations\Runtime.php(38): class_exists('Magento\\Framewo...')
#4 lib\internal\Magento\Framework\Interception\Config\Config.php(153): Magento\Framework\ObjectManager\Relations\Runtime->has('Magento\\Framewo...')
#5 lib\internal\Magento\Framework\Interception\Config\Config.php(176): Magento\Framework\Interception\Config\Config->_inheritInterception('Magento\\Framewo...')
#6 lib\internal\Magento\Framework\Interception\ObjectManager\Config\Developer.php(39): Magento\Framework\Interception\Config\Config->hasPlugins('Magento\\Framewo...')
#7 lib\internal\Magento\Framework\ObjectManager\Factory\Dynamic\Developer.php(70): Magento\Framework\Interception\ObjectManager\Config\Developer->getInstanceType('Magento\\Framewo...')
#8 lib\internal\Magento\Framework\ObjectManager\ObjectManager.php(71): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create('Magento\\Framewo...')
#9 lib\internal\Magento\Framework\ObjectManager\Factory\AbstractFactory.php(236): Magento\Framework\ObjectManager\ObjectManager->get('Magento\\Framewo...')
#10 lib\internal\Magento\Framework\ObjectManager\Factory\Dynamic\Developer.php(53): Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument(Array, 'Magento\\Framewo...', NULL, 'cache', 'Magento\\Framewo...')
#11 lib\internal\Magento\Framework\ObjectManager\Factory\Dynamic\Developer.php(82): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments('Magento\\Framewo...', Array, Array)
#12 lib\internal\Magento\Framework\ObjectManager\ObjectManager.php(71): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create('Magento\\Framewo...')
#13 var\generation\Magento\Framework\App\ResourceConnection\Config\Proxy.php(84): Magento\Framework\ObjectManager\ObjectManager->get('\\Magento\\Framew...')
#14 var\generation\Magento\Framework\App\ResourceConnection\Config\Proxy.php(95): Magento\Framework\App\ResourceConnection\Config\Proxy->_getSubject()
#15 lib\internal\Magento\Framework\App\ResourceConnection.php(91): Magento\Framework\App\ResourceConnection\Config\Proxy->getConnectionName('default')
#16 lib\internal\Magento\Framework\Model\ResourceModel\Db\AbstractDb.php(322): Magento\Framework\App\ResourceConnection->getConnection('default')
#17 lib\internal\Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection.php(123): Magento\Framework\Model\ResourceModel\Db\AbstractDb->getConnection()
#18 app\code\Magento\Store\Model\ResourceModel\Config\Collection\Scoped.php(48): Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection->__construct(Object(Magento\Framework\Data\Collection\EntityFactory), Object(Magento\Framework\Logger\Monolog), Object(Magento\Framework\Data\Collection\Db\FetchStrategy\Query), Object(Magento\Framework\Event\Manager\Proxy), NULL, Object(Magento\Config\Model\ResourceModel\Config\Data))
#19 lib\internal\Magento\Framework\ObjectManager\Factory\AbstractFactory.php(111): Magento\Store\Model\ResourceModel\Config\Collection\Scoped->__construct(Object(Magento\Framework\Data\Collection\EntityFactory), Object(Magento\Framework\Logger\Monolog), Object(Magento\Framework\Data\Collection\Db\FetchStrategy\Query), Object(Magento\Framework\Event\Manager\Proxy), Object(Magento\Config\Model\ResourceModel\Config\Data), 'default', NULL, NULL)
#20 lib\internal\Magento\Framework\ObjectManager\Factory\Dynamic\Developer.php(89): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('Magento\\Store\\M...', Array)
#21 lib\internal\Magento\Framework\ObjectManager\ObjectManager.php(57): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create('Magento\\Store\\M...', Array)
#22 var\generation\Magento\Store\Model\ResourceModel\Config\Collection\ScopedFactory.php(44): Magento\Framework\ObjectManager\ObjectManager->create('\\Magento\\Store\\...', Array)
#23 app\code\Magento\Store\Model\Config\Reader\DefaultReader.php(63): Magento\Store\Model\ResourceModel\Config\Collection\ScopedFactory->create(Array)
#24 lib\internal\Magento\Framework\App\Config\ScopePool.php(84): Magento\Store\Model\Config\Reader\DefaultReader->read()
#25 app\code\Magento\Backend\App\Config.php(41): Magento\Framework\App\Config\ScopePool->getScope('default', NULL)
#26 app\code\Magento\Backend\App\Area\FrontNameResolver.php(73): Magento\Backend\App\Config->getValue('admin/url/use_c...')
#27 app\code\Magento\Backend\Helper\Data.php(206): Magento\Backend\App\Area\FrontNameResolver->getFrontName(false)
#28 app\code\Magento\Backend\App\Request\PathInfoProcessor.php(46): Magento\Backend\Helper\Data->getAreaFrontName()
#29 var\generation\Magento\Backend\App\Request\PathInfoProcessor\Proxy.php(95): Magento\Backend\App\Request\PathInfoProcessor->process(Object(Magento\Framework\App\Request\Http), '/catalog/produc...')
#30 lib\internal\Magento\Framework\App\Request\Http.php(161): Magento\Backend\App\Request\PathInfoProcessor\Proxy->process(Object(Magento\Framework\App\Request\Http), '/catalog/produc...')
#31 lib\internal\Magento\Framework\HTTP\PhpEnvironment\Request.php(194): Magento\Framework\App\Request\Http->setPathInfo()
#32 lib\internal\Magento\Framework\App\Request\Http.php(204): Magento\Framework\HTTP\PhpEnvironment\Request->getPathInfo()
#33 lib\internal\Magento\Framework\App\Http.php(110): Magento\Framework\App\Request\Http->getFrontName()
#34 lib\internal\Magento\Framework\App\Bootstrap.php(258): Magento\Framework\App\Http->launch()
#35 index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#36 {main}

https://github.com/magento/magento2/issues/2321

The solution is to compile the code before serving any requests.