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


C++ atomic::fetch_and_add方法代码示例

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


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

示例1: ccr_dec_workers

// Finalizes a worker thread
static int ccr_dec_workers(lua_State *L)
{
    int count = (int)luaL_checkinteger(L, 1);
    lua_getfield(L, LUA_REGISTRYINDEX, CCR_SELF);
    process_t *proc = (process_t*)lua_touserdata(L, -1);

    // checks if the calling process is a main process
    if(proc->main)
    {
        if (thr_pool.size() - count < THR_SIZE)
        {
            lua_pushinteger(L, 0);
            lua_pushstring(L, "thread pool is already at the minimum size");
            return 2;
        }

        // sets the numbers threads to kill
        free_workers.fetch_and_add(count);
        // sets the flag indication to kill threads
        free_flag.compare_and_swap(true, false);
        // returns the current number of threads in the pool
        lua_pushinteger(L, (lua_Integer) thr_pool.size() - count);
        return 1;
    }
    lua_pushinteger(L, 0);
    lua_pushstring(L, "only a main process could free threads");
    return 2;
}
开发者ID:DaiYamatta,项目名称:ALua,代码行数:29,代码来源:ccr.cpp

示例2: create_key

 // creates or finds an available fake TLS key
 inline void create_key( fake_key_t &k ) {
     if ( !(free_stack && pop_if_present( k )) ) {
         k = next_key.fetch_and_add(1);     
     } 
 }
开发者ID:atzannes,项目名称:LazyTBB-v3.0,代码行数:6,代码来源:enumerable_thread_specific.cpp


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