本文整理汇总了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;
}
示例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);
}
}