Buying same product simultaneously in drupal commerce
Check out Commerce Stock - https://www.drupal.org/project/commerce_stock. The module itself will expose hooks for controlling stock. Or there are sub modules it provides - Simple Stock and Simple Stock Rules - which add an integer field and use Rules to validate purchases.

This runs on Add to Cart, Can Checkout, and prior to purchase.