当前位置: 首页>>代码示例>>C++>>正文


C++ shared_mutex::unlock方法代码示例

本文整理汇总了C++中std::shared_mutex::unlock方法的典型用法代码示例。如果您正苦于以下问题:C++ shared_mutex::unlock方法的具体用法?C++ shared_mutex::unlock怎么用?C++ shared_mutex::unlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::shared_mutex的用法示例。


在下文中一共展示了shared_mutex::unlock方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
#if _LIBCPP_STD_VER > 11
    {
        m.lock();
        std::vector<std::thread> v;
        for (int i = 0; i < 5; ++i)
            v.push_back(std::thread(f1));
        std::this_thread::sleep_for(ms(250));
        m.unlock();
        for (auto& t : v)
            t.join();
    }
    {
        m.lock();
        std::vector<std::thread> v;
        for (int i = 0; i < 5; ++i)
            v.push_back(std::thread(f2));
        std::this_thread::sleep_for(ms(300));
        m.unlock();
        for (auto& t : v)
            t.join();
    }
#endif  // _LIBCPP_STD_VER > 11
}
开发者ID:Bhudipta,项目名称:minix,代码行数:25,代码来源:mutex_time_point.pass.cpp

示例2: insert

    /**
     * insert method; find the right place in the list, add val so that it is
     * in sorted order; if val is already in the list, exit without inserting
     */
    void insert(int val)
    {
	mtx.lock();
        // traverse the list to find the insertion point
        Node* prev =sentinel;
        Node* curr = prev->next;
        while (curr != NULL) {
            if (curr->val >= val)
                break;
            prev = curr;
            curr = prev->next;
        }

        // now insert new_node between prev and curr
        //
        // NB: if the test fails, it means we quit the above loop on account
        // of /finding/ val, in which case we just exit
        if (!curr || ((curr->val) > val)) {
            // create the new node
            Node* i = (Node*)malloc(sizeof(Node));
            i->val = val;
            i->next = curr;
            // insert it
            prev->next = i;
        }
	mtx.unlock();
    }
开发者ID:wangamanda,项目名称:parallel-computing,代码行数:31,代码来源:List.hpp

示例3: remove

    /**
     *  To remove from the list, we need to keep a pointer to the previous
     *  node, too.  Note that this is much easier on account of us having a
     *  sentinel
     */
    void remove(int val)
    {
        mtx.lock();
        // find the node whose val matches the request
        Node* prev = sentinel;
        Node* curr = prev->next;
        while (curr != NULL) {
            // if we find the node, disconnect it and end the search
            if (curr->val == val) {
                prev->next = curr->next;

                // delete curr...
                free(curr);
                break;
            }
            else if (curr->val > val) {
                // this means the search failed
                break;
            }
            // advance one node
            prev = curr;
            curr = prev->next;
        }
	mtx.unlock();
    }
开发者ID:wangamanda,项目名称:parallel-computing,代码行数:30,代码来源:List.hpp

示例4: main

int main()
{
    m.lock();
    std::thread t(f);
    std::this_thread::sleep_for(WaitTime);
    m.unlock();
    t.join();
}
开发者ID:jfbastien,项目名称:libcxx,代码行数:8,代码来源:lock.pass.cpp

示例5: f

void f()
{
    time_point t0 = Clock::now();
    m.lock();
    time_point t1 = Clock::now();
    m.unlock();
    ns d = t1 - t0 - WaitTime;
    assert(d < Tolerance);  // within tolerance
}
开发者ID:jfbastien,项目名称:libcxx,代码行数:9,代码来源:lock.pass.cpp

示例6: main

int main()
{
    m.lock();
    std::vector<std::thread> v;
    for (int i = 0; i < 5; ++i)
        v.push_back(std::thread(f));
    std::this_thread::sleep_for(ms(250));
    m.unlock();
    for (auto& t : v)
        t.join();
}
开发者ID:markus-oberhumer,项目名称:libcxx,代码行数:11,代码来源:try_lock_shared.pass.cpp

示例7: main

int main()
{
    m.lock();
    std::vector<std::thread> v;
    for (int i = 0; i < 5; ++i)
        v.push_back(std::thread(f));
    std::this_thread::sleep_for(WaitTime);
    m.unlock();
    for (auto& t : v)
        t.join();
    m.lock_shared();
    for (auto& t : v)
        t = std::thread(g);
    std::thread q(f);
    std::this_thread::sleep_for(WaitTime);
    m.unlock_shared();
    for (auto& t : v)
        t.join();
    q.join();
}
开发者ID:markus-oberhumer,项目名称:libcxx,代码行数:20,代码来源:lock_shared.pass.cpp


注:本文中的std::shared_mutex::unlock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。