C++11æ¨æºã©ã¤ãã©ãªã®std::mutexãªãã¸ã§ã¯ãã§ã¯ãããã¯åå¾ï¼è§£æ¾ãåä¸ã¹ã¬ãã*1ããè¡ããªããã°ãªããªããï¼N3337 30.2.5.2/p3ï¼ m.unlock() Requires: The current execution agent shall hold a lock on m. ãã®å¶ç´æ¡ä»¶ã®ãããä¸è¨ã³ã¼ãã®mutexãªãã¸ã§ã¯ãå©ç¨ã¯æªå®ç¾©åä½(undefined behavior)ãå¼ãèµ·ããã #include <thread> #include <mutex> std::mutex mtx; // mutexãªãã¸ã§ã¯ã int resource; // ä¿è·å¯¾è±¡ã®ãªã½ã¼ã¹ void proc() { // resourceã使ãå¦çB mtx.unlock(); // (2) NGï¼å¥ã¹ã¬ããã§ããã¯è§£æ¾...ããã //... } int mai
{{#tags}}- {{label}}
{{/tags}}