gccã®__attribute__((cleanup(fn))) ã便å©ããã件ã«ã¤ãã¦ã C++ã§ã³ã¼ããæ¸ãã¨ãã¯ãRAIIã¨ãå¼ã°ãã¦ããã¤ãã£ãªã ã使ãã°ããåãã®éããããã¯ããmutexãæåã§éæ¾ããå¿ è¦ããªãã§ãããnewãããªãã¸ã§ã¯ããæåã§deleteããå¿ è¦ããªãã§ãã void Baz::boo() const { boost::mutex::scoped_lock lock(mutex); // ... return; // lockå¤æ°ã®ãã¹ãã©ã¯ã¿ã§èªåéæ¾ãæåã§ã®éæ¾ä¸è¦ }ã§ãCè¨èªã ã¨ãå½ç¶ãªããæåã§éæ¾ããªãã¨ããã¾ãããè¤æ°ç®æã§returnãã¦ããå ´åãªã©ãã¿ã¤ããé¢åèããã int foo() { pthread_mutex_lock(&mutex); // ... if (hogehoge) { pthread_mutex_unlock
{{#tags}}- {{label}}
{{/tags}}