How do I make a critical section with Boost?

前端 未结 2 678
礼貌的吻别
礼貌的吻别 2021-01-17 15:40

For my cross-platform application I have started to use Boost, but I can\'t understand how I can implement code to reproduce behavior of Win32\'s critical section or .Net\'s

2条回答
  •  借酒劲吻你
    2021-01-17 16:18

    With boost you can use boost::lock_guard<> class:

    class test
    {
    public:
     void testMethod()
     {
      // this section is not locked
      {
       boost::lock_guard lock(m_guard);
       // this section is locked
      }
      // this section is not locked
     }
    private:
        boost::recursive_mutex m_guard;
    };
    

    PS These classes located in Boost.Thread library.

提交回复
热议问题