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


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

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


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

示例1: test_timed_executor

void test_timed_executor(std::array<std::size_t, 4> expected)
{
    typedef typename hpx::traits::executor_execution_category<
            Executor
        >::type execution_category;

    HPX_TEST((std::is_same<
            hpx::parallel::execution::sequenced_execution_tag,
            execution_category
        >::value));

    count_sync.store(0);
    count_apply.store(0);
    count_sync_at.store(0);
    count_apply_at.store(0);

    Executor exec;

    test_timed_apply(exec);
    test_timed_sync(exec);
    test_timed_async(exec);

    HPX_TEST_EQ(expected[0], count_sync.load());
    HPX_TEST_EQ(expected[1], count_apply.load());
    HPX_TEST_EQ(expected[2], count_sync_at.load());
    HPX_TEST_EQ(expected[3], count_apply_at.load());
}
开发者ID:atrantan,项目名称:hpx,代码行数:27,代码来源:minimal_timed_sync_executor.cpp

示例2: overlay_initialized

/**
 * The environment should be initialised exactly once during shared library initialisation.
 * Prior to that, all operations work in pass-through mode.
 * To overcome undefined global initialisation order, we use a local static variable.
 * This variable is accesd by a single writer (lib (de)initialisation), and multiple readers (exported operations).
 * Writer: toggle == true (toggles is_initialised)
 * Reader: toggle == false (returns the current value of is_initialised)
 *
 * NOTE: pthread_once initialisation for the overlay leads to a deadlock due to a re-entry situation:
 * - environment ctor is called the first time via pthread_once
 * - which leads a write somewhere (probably to a socket during client initialisation)
 * - which then enters the pthread_once initialisation mechanism again and blocks deadlocks
 */
bool overlay_initialized(bool toggle /* defaults to: false */) {
  static boost::atomic<bool> is_initilized(false);

  // writer
  if(toggle) {
    return is_initilized.exchange(!is_initilized.load());
  }

  // reader
  return is_initilized.load();
}
开发者ID:2510,项目名称:xtreemfs,代码行数:24,代码来源:preload.cpp

示例3: default_executor

    scheduled_executor default_executor()
    {
        if (!default_executor_instance.load())
        {
            scheduled_executor& default_exec =
                scheduled_executor::default_executor();
            scheduled_executor empty_exec;

            default_executor_instance.compare_exchange_strong(
                empty_exec, default_exec);
        }
        return default_executor_instance.load();
    }
开发者ID:HadrienG2,项目名称:hpx,代码行数:13,代码来源:thread_executor.cpp

示例4: calc_block

void calc_block(
    hpxla::local_matrix_view<boost::int64_t>& H 
  , hpxla::local_matrix_view<hpx::future<void> >& C // Control matrix.
  , coords start   // The start of our cell block. 
  , coords end     // The end of our cell block.
  , coords control // Our location in the control matrix.
  , std::string const& a
  , std::string const& b
    )
{
    // TODO: Handle this with hpx::wait_all?
    C(control.i,   control.j-1).get(); 
    C(control.i-1, control.j-1).get(); 
    C(control.i-1, control.j  ).get(); 

    winner local_best = H_best.load();

    // Generate scores.
    for (boost::uint32_t i = start.i; i < end.i; ++i)
    {
        for (boost::uint32_t j = start.j; j < end.j; ++j)
        {
            H(i, j) = calc_cell(i, j, a[i-1], b[j-1]
              , H(i,   j-1) // left
              , H(i-1, j-1) // diagonal 
              , H(i-1, j  ) // up
            ); 

            if (H(i, j) > local_best.value)
            {
                local_best.value = H(i, j);
                local_best.i = i;
                local_best.j = j;
            } 
        }
    }

    winner H_best_old = H_best.load(); 

    while (true)
    {
        if (local_best.value > H_best_old.value)
        {
            if (H_best.compare_exchange_weak(H_best_old, local_best))
                break;
        }
        else
            break;
    }
}
开发者ID:akemp,项目名称:hpxla,代码行数:50,代码来源:blocked_smp_smith_waterman.cpp

示例5: hpx_main

int hpx_main(int argc, char** argv_init)
{
    hpx::new_<test_server>(hpx::find_here(), moveonly()).get();
    HPX_TEST_EQ(constructed_from_moveonly.load(), 1);

    moveable o;
    hpx::new_<test_server>(hpx::find_here(), o).get();
    HPX_TEST_EQ(constructed_from_moveable.load(), 1);

    hpx::new_<test_server>(hpx::find_here(), moveable()).get();
    HPX_TEST_EQ(constructed_from_moveable.load(), 2);

    return hpx::finalize();
}
开发者ID:HadrienG2,项目名称:hpx,代码行数:14,代码来源:moveonly_constructor_arguments_1405.cpp

示例6: increment

void increment(hpx::id_type const& there, boost::int32_t i)
{
    locality_id = hpx::get_locality_id();

    accumulator += i;
    hpx::apply(receive_result_action(), there, accumulator.load());
}
开发者ID:NextGenIntelligence,项目名称:hpx,代码行数:7,代码来源:apply_colocated.cpp

示例7: get_and_reset_value

 inline T get_and_reset_value(boost::atomic<T>& value, bool reset)
 {
     T result = value.load();
     if (reset)
         value.store(0);
     return result;
 }
开发者ID:atrantan,项目名称:hpx,代码行数:7,代码来源:get_and_reset_value.hpp

示例8: try_recursive_lock

 bool try_recursive_lock(thread_id_type current_thread_id)
 {
     if (locking_thread_id.load(boost::memory_order_acquire) ==
         current_thread_id)
     {
         util::register_lock(this);
         ++recursion_count;
         return true;
     }
     return false;
 }
开发者ID:HadrienG2,项目名称:hpx,代码行数:11,代码来源:recursive_mutex.hpp

示例9: call_void

    void call_void()
    {
        ++count_call_void;

        // make sure this function is not concurrently invoked
        HPX_TEST_EQ(count_active_call_void.fetch_add(1) + 1, 1);

        hpx::this_thread::suspend(boost::chrono::microseconds(100));

        --count_active_call_void;
        HPX_TEST_EQ(count_active_call_void.load(), 0);
    }
开发者ID:AntonBikineev,项目名称:hpx,代码行数:12,代码来源:action_invoke_no_more_than.cpp

示例10: main

int main()
{
    {
        hpx::threads::executors::local_priority_queue_executor exec(4);
        for (int i = 0; i != 100; ++i)
            hpx::async(exec, &doit);
    }

    HPX_TEST_EQ(counter.load(), 100);

    return hpx::util::report_errors();
}
开发者ID:7ev3n,项目名称:hpx,代码行数:12,代码来源:thread_pool_executor_1112.cpp

示例11: test_remote_async_cb

void test_remote_async_cb(hpx::id_type const& target)
{
    typedef hpx::components::client<decrement_server> decrement_client;

    {
        decrement_client dec_f =
            hpx::components::new_<decrement_client>(target);

        call_action call;

        callback_called.store(0);
        hpx::future<std::int32_t> f1 = hpx::async_cb(call, dec_f, &cb, 42);
        HPX_TEST_EQ(f1.get(), 41);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        hpx::future<std::int32_t> f2 =
            hpx::async_cb(hpx::launch::all, call, dec_f, &cb, 42);
        HPX_TEST_EQ(f2.get(), 41);
        HPX_TEST_EQ(callback_called.load(), 1);
    }

    {
        decrement_client dec_f =
            hpx::components::new_<decrement_client>(target);
        hpx::id_type dec = dec_f.get_id();

        callback_called.store(0);
        hpx::future<std::int32_t> f1 =
            hpx::async_cb<call_action>(dec_f, &cb, 42);
        HPX_TEST_EQ(f1.get(), 41);
        HPX_TEST_EQ(callback_called.load(), 1);

        callback_called.store(0);
        hpx::future<std::int32_t> f2 =
            hpx::async_cb<call_action>(hpx::launch::all, dec_f, &cb, 42);
        HPX_TEST_EQ(f2.get(), 41);
        HPX_TEST_EQ(callback_called.load(), 1);
    }
}
开发者ID:khuck,项目名称:hpx,代码行数:40,代码来源:async_cb_remote_client.cpp

示例12: sizeof

TORRENT_NO_RETURN TORRENT_EXPORT void assert_fail(char const* expr, int line
	, char const* file, char const* function, char const* value, int kind)
{
#ifdef TORRENT_PRODUCTION_ASSERTS
	// no need to flood the assert log with infinite number of asserts
	if (assert_counter.fetch_add(1) + 1 > 500) return;
#endif

	char stack[8192];
	stack[0] = '\0';
	print_backtrace(stack, sizeof(stack), 0);

	char const* message = "assertion failed. Please file a bugreport at "
		"http://code.google.com/p/libtorrent/issues\n"
		"Please include the following information:\n\n"
		"version: " LIBTORRENT_VERSION "\n"
		LIBTORRENT_REVISION "\n";

	switch (kind)
	{
		case 1:
			message = "A precondition of a libtorrent function has been violated.\n"
				"This indicates a bug in the client application using libtorrent\n";
	}
	  
	assert_print("%s\n"
#ifdef TORRENT_PRODUCTION_ASSERTS
		"#: %d\n"
#endif
		"file: '%s'\n"
		"line: %d\n"
		"function: %s\n"
		"expression: %s\n"
		"%s%s\n"
		"stack:\n"
		"%s\n"
		, message
#ifdef TORRENT_PRODUCTION_ASSERTS
		, assert_counter.load()
#endif
		, file, line, function, expr
		, value ? value : "", value ? "\n" : ""
		, stack);

	// if production asserts are defined, don't abort, just print the error
#ifndef TORRENT_PRODUCTION_ASSERTS
 	// send SIGINT to the current process
 	// to break into the debugger
 	raise(SIGINT);
 	abort();
#endif
}
开发者ID:snowyu,项目名称:libtorrent,代码行数:52,代码来源:assert.cpp

示例13: random_outlets

void random_outlets(double spawn_every=0.0, double duration=0.0, string name=string(), string type=string(), int numchan=0, lsl::channel_format_t fmt=lsl::cf_undefined, double srate=0.0, double seconds_between_failures=0.0, int chunk_len=0) {
	if (spawn_every == 0.0)
		spawn_every = spawn_outlet_interval;
	while(true) {
        try {
			if (num_outlets.load() < max_inlets)
				boost::thread tmp(&run_outlet,duration,name,type,numchan,fmt,srate,seconds_between_failures,chunk_len);
		} catch(std::exception &e) {
			std::cerr << "Could not spawn a new outlet thread: " << e.what() << std::endl;
        }		
		boost::this_thread::sleep(boost::posix_time::millisec((boost::int64_t)(1000*spawn_every)));
	}
}
开发者ID:MindContact,项目名称:labstreaminglayer,代码行数:13,代码来源:StressTest.cpp

示例14: random_inlets

void random_inlets(double spawn_every=0.0, double duration=0.0, string name=string(), string type=string(), int in_chunks=-1, int request_info=-1, int request_time=-1, double seconds_between_failures=0.0) {
	if (spawn_every == 0.0)
		spawn_every = spawn_inlet_interval;
	while(true) {
        try {
			if (num_inlets.load() < max_outlets)
				boost::thread tmp(&run_inlet,duration,name,type,in_chunks,request_info,request_time,seconds_between_failures);
		} catch(std::exception &e) {
			std::cerr << "Could not spawn a new inlet thread: " << e.what() << std::endl;
        }		
		boost::this_thread::sleep(boost::posix_time::millisec((boost::int64_t)(1000*spawn_every)));
	}
}
开发者ID:MindContact,项目名称:labstreaminglayer,代码行数:13,代码来源:StressTest.cpp

示例15: streamWriterThread

static void streamWriterThread() {
    try {
        while (true) {
            boost::this_thread::sleep_for(boost::chrono::seconds(2));
            
            int lastStatus = 200;
            auto lastRowIndex = writeRowIndex.load();
            
            while (readRowIndex < lastRowIndex) {
                for (auto i = readRowIndex; i < lastRowIndex; ++i) {
                    auto& row = logRows[i % maxLogRows];

                    if (row.status != lastStatus) {
                        if (row.status >= 500) {
                            std::cout << termcolor::red;
                        } else if (row.status >= 400) {
                            std::cout << termcolor::grey << termcolor::bold;
                        } else if (row.status >= 300) {
                            std::cout << termcolor::yellow;
                        } else {
                            std::cout << termcolor::reset;
                        }

                        lastStatus = row.status;
                    }

                    std::cout << row.data << "\n";
                }

                readRowIndex = lastRowIndex;
                lastRowIndex = writeRowIndex.load();
            }                        
            
            std::cout << termcolor::reset << std::flush;                        
        }
    } catch (boost::thread_interrupted&) {
    }
}
开发者ID:AppleWatchHipster,项目名称:AvanceDB,代码行数:38,代码来源:http_server_log.cpp


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