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


C++ SpinLock::lock方法代码示例

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


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

示例1: ThreadingManagerOMP

    ThreadingManagerOMP(int req = -1)
    : start_counter(1),
      barrier_protocol(*static_cast<ThreadingManager*>(this))
    {
        assert(req == -1);

        // In the OpenMP backend, the ThreadManager is instantiated
        // in a serial section, so in contrast to the threaded backend
        // we do not know the number of threads here.
        // Instead we find out when we are called again in thread_main()
        startup_lock.lock();
        lock_workers_initialized.lock();

        Options::ThreadAffinity::init();
    }
开发者ID:ahellander,项目名称:superglue,代码行数:15,代码来源:threadingmanager_omp.hpp

示例2: func

void func(int i)
{
	g_lock.lock();
	std::this_thread::sleep_for(std::chrono::milliseconds(10));
	std::cout << std::this_thread::get_id() << "add : " << i << std::endl;
	sum++;
	g_lock.unlock();
}
开发者ID:LeftThink,项目名称:CodeTricks,代码行数:8,代码来源:test.cpp

示例3: init_worker

    void init_worker(int id) {
        Options::ThreadAffinity::pin_workerthread(id);
        // allocate Worker on thread
        TaskExecutor<Options> *te = new TaskExecutor<Options>(id, *this);

        // wait until main thread has initialized the threadmanager
        startup_lock.lock();
        startup_lock.unlock();

        threads[id] = te;
        task_queues[id] = &te->get_task_queue();

        Atomic::increase(&start_counter);

        lock_workers_initialized.lock();
        lock_workers_initialized.unlock();

        te->work_loop();
    }
开发者ID:ahellander,项目名称:superglue,代码行数:19,代码来源:threadingmanager_omp.hpp

示例4: stop

    void stop() {
        if (get_thread_num() != 0) {
            
            // workers don't come here until terminate() has been called

            int nv = Atomic::decrease_nv(&start_counter);

            // wait until all workers reached this step
            // all threads must agree that we are shutting
            // down before we can continue and invoke the
            // destructor
            startup_lock.lock();
            startup_lock.unlock();
            return;
        }

        start_executing(); // make sure threads have been started, or we will wait forever in barrier
        barrier_protocol.barrier(*threads[0]);

        startup_lock.lock();

        for (int i = 1; i < get_num_cpus(); ++i)
            threads[i]->terminate();


        // wait for all threads to join
        while (start_counter != 1)
            Atomic::rep_nop();

        // signal that threads can destruct
        startup_lock.unlock();

        for (int i = 1; i < get_num_cpus(); ++i)
            delete threads[i];

        delete [] threads;
        delete [] task_queues;
    }
开发者ID:ahellander,项目名称:superglue,代码行数:38,代码来源:threadingmanager_omp.hpp

示例5: debug_bytes_free

 /**
  * Return the number of bytes consumed by all free list blocks.
  *
  * This does not define the number of bytes available for actual usable allocation, and should not be used
  * by non-implementation code outside of unit tests or debugging.
  */
 vm_size_t debug_bytes_free () {
     vm_size_t bytes_free = 0;
     
     _lock.lock();
     control_block *first = _free_list;
     for (control_block *b = _free_list; b != NULL; b = b->_next) {
         bytes_free += b->_size;
         
         if (b->_next == first)
             break;
     }
     _lock.unlock();
     
     return bytes_free;
 }
开发者ID:BossKing10086,项目名称:plcrashreporter,代码行数:21,代码来源:AsyncAllocator.hpp

示例6: TEST

    TEST(ParallelUtils,SpinLock) {

        const int N = 1000000;

        SpinLock lock;

        volatile int c =0;

        #pragma omp parallel for num_threads(4)
        for(int i=0; i<N; i++) {
            lock.lock();
            c++;
            lock.unlock();
        }

        EXPECT_EQ(N, c);

    }
开发者ID:cotsog,项目名称:souffle,代码行数:18,代码来源:parallel_utils_test.cpp

示例7: getDefault

		Font Font::getDefault()
		{
			static Font font;
			static SpinLock lock;

			lock.lock();

			if (font.getHandle() == nullptr)
			{
				jni::Class Button("libnative/ui/TextComponent");
				jni::method_t viewConstructor = Button.getConstructor("(Landroid/content/Context;)V");
				jni::Object button = Button.newInstance(viewConstructor, (jni::Object*) App::getAppHandle());

				// Android already scales its default fonts.
				font._size = button.call<float>("getScaledTextSize");
				font._shared->handle = new jni::Object(button.call<jni::Object>("getTypeface()Landroid/graphics/Typeface;"));
			}

			lock.release();

			return font;
		}
开发者ID:mitchdowd,项目名称:native,代码行数:22,代码来源:font.cpp

示例8:

	SpinGuard(SpinLock& mutex) : _mutex(&mutex){
		_mutex->lock();
	}
开发者ID:ankithbti,项目名称:OrderBookSketch,代码行数:3,代码来源:SpinLock.hpp

示例9: func

void func(int n)
{
    g_Lock.lock();
    std::cout << "Output from thread: " << n << std::endl;
    g_Lock.unlock();
}
开发者ID:renc,项目名称:coding_exercises,代码行数:6,代码来源:ex8_threadlock.cpp


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