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


C++ std::atomic_flag类代码示例

本文整理汇总了C++中std::atomic_flag的典型用法代码示例。如果您正苦于以下问题:C++ atomic_flag类的具体用法?C++ atomic_flag怎么用?C++ atomic_flag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Error

void Sys::Error(Str::StringRef message)
{
	// Only try sending an ErrorMsg once
	static std::atomic_flag errorEntered;
	if (!errorEntered.test_and_set()) {
		// Disable checks for sending sync messages when handling async messages.
		// At this point we don't really care since this is an error.
		VM::rootChannel.canSendSyncMsg = true;

		// Try to tell the engine about the error, but ignore errors doing so.
		try {
			VM::SendMsg<VM::ErrorMsg>(message);
		} catch (...) {}
	}

#ifdef BUILD_VM_IN_PROCESS
	// Then engine will close the root socket when it wants us to exit, which
	// will trigger an error in the IPC functions. If we reached this point then
	// we try to exit the thread semi-cleanly by throwing an exception.
	throw ExitException();
#else
	// The SendMsg should never return since the engine should kill our process.
	// Just in case it doesn't, exit here.
	_exit(255);
#endif
}
开发者ID:JacksonTech,项目名称:Unvanquished,代码行数:26,代码来源:VMMain.cpp

示例2: runtime_error

Terminator::Terminator() {
  static std::atomic_flag created = ATOMIC_FLAG_INIT;
  if (created.test_and_set()) {
    throw std::runtime_error("Terminator may be crated exactly once.");
  }

  std::atomic_init(&this->should_terminate_, false);
  signal_handler_ = SpawnThread(this);
}
开发者ID:dpantele,项目名称:acc,代码行数:9,代码来源:Terminator.cpp

示例3: f

namespace atomTest{
	std::atomic_flag lock = ATOMIC_FLAG_INIT;

	void f(int n)
	{
		while(lock.test_and_set(std::memory_order_acquire)){
			cout<<"waiting from thread "<< n <<endl;
		}

		cout<<"thread "<< n <<"starts working!"<<endl;
	}

	void g(int n)
	{
		cout<<"thread "<< n << "is going to start"<<endl;
		lock.clear();
		cout<<"thread "<< n << "starts working"<<endl;
	}

	void test()
	{
		lock.test_and_set();
		thread t1(f, 1);
		thread t2(g, 2);

		t1.join();
		usleep(100); //posix unix
		t2.join();
	}
}
开发者ID:kexianda,项目名称:misc,代码行数:30,代码来源:multiThreadTest.cpp

示例4: Update

/// <summary>
/// Updates the cover art.
/// </summary>
void Update() {
  // Set while the updater thread is running.
  static std::atomic_flag closed = ATOMIC_FLAG_INIT;

  if (!closed.test_and_set()) {
    std::thread([] () {
      TextFunctions::_Update();
      SendMessage(gLSModule.GetMessageWindow(), WindowMessages::WM_TEXTUPDATENOTIFY, 0, 0);

      for (auto &coverArt : gCoverArt) {
        coverArt.second.Update();
      }

      closed.clear();
    }).detach();
  }
}
开发者ID:Superxwolf,项目名称:nModules,代码行数:20,代码来源:nMediaInfo.cpp

示例5: sigint_handler

// CODETAG_IOR_SIGNALS
//++
// Details: The SIGINT signal is sent to a process by its controlling terminal
// when a
//          user wishes to interrupt the process. This is typically initiated by
//          pressing
//          Control-C, but on some systems, the "delete" character or "break"
//          key can be
//          used.
//          Be aware this function may be called on another thread besides the
//          main thread.
// Type:    Function.
// Args:    vSigno  - (R) Signal number.
// Return:  None.
// Throws:  None.
//--
void sigint_handler(int vSigno) {
#ifdef _WIN32 // Restore handler as it is not persistent on Windows
  signal(SIGINT, sigint_handler);
#endif
  static std::atomic_flag g_interrupt_sent = ATOMIC_FLAG_INIT;
  CMIDriverMgr &rDriverMgr = CMIDriverMgr::Instance();
  lldb::SBDebugger *pDebugger = rDriverMgr.DriverGetTheDebugger();
  if (pDebugger != nullptr) {
    if (!g_interrupt_sent.test_and_set()) {
      pDebugger->DispatchInputInterrupt();
      g_interrupt_sent.clear();
    }
  }

  // Send signal to driver so that it can take suitable action
  rDriverMgr.DeliverSignal(vSigno);
}
开发者ID:llvm-project,项目名称:lldb,代码行数:33,代码来源:MIDriverMain.cpp

示例6: handler

static void handler()
{
  // Avoid doing crazy things if we get an uncaught exception inside
  // an uncaught exception
  static std::atomic_flag lock = ATOMIC_FLAG_INIT;
  if (lock.test_and_set()) {
    XBT_ERROR("Multiple uncaught exceptions");
    std::abort();
  }

  // Get the current backtrace and exception
  auto e = std::current_exception();
  auto bt = backtrace();
  try {
    std::rethrow_exception(e);
  }

  // We manage C++ exception ourselves
  catch (std::exception& e) {
    logException(xbt_log_priority_critical, "Uncaught exception", e);
    showBacktrace(bt);
    std::abort();
  }

  // We don't know how to manage other exceptions
  catch (...) {
    // If there was another handler let's delegate to it
    if (previous_terminate_handler)
      previous_terminate_handler();
    else {
      XBT_ERROR("Unknown uncaught exception");
      showBacktrace(bt);
      std::abort();
    }
  }

}
开发者ID:fabienchaix,项目名称:simgrid,代码行数:37,代码来源:exception.cpp

示例7: append_number

void append_number(int x)
{
	while (lock_stream.test_and_set()) {
	}
	stream << "thread #" << x << '\n';
	lock_stream.clear();
}
开发者ID:parsons-smith,项目名称:CPP-11,代码行数:7,代码来源:atomic_flag2.cpp

示例8: step

void step()
{
	while(lock_vis.test_and_set()){}
	for(auto i = elements->begin(); i != elements->end(); ++i)
	{
		if(i->step())
		{
			i = elements->erase(i);
			--i;
		}
	}
	lock_vis.clear();
}
开发者ID:mcnutty26,项目名称:octoDrone,代码行数:13,代码来源:Visualisation.cpp

示例9: g

void g(int n)
{
    using namespace std::chrono_literals;
    std::this_thread::sleep_for(2s);
    std::cout << "Thread " << n << " is going to clear the flag." << std::endl;
    lock.clear();                                                       // 解锁
}
开发者ID:tomatolionz,项目名称:cplusplus,代码行数:7,代码来源:main.cpp

示例10: initializeNotifier

void* initializeNotifier(void (*process)(uint64_t, void*), void *param, int32_t *status)
{
	if (!process) {
		*status = NULL_PARAMETER;
		return nullptr;
	}
	if (!notifierAtexitRegistered.test_and_set())
		std::atexit(cleanupNotifierAtExit);
	if (notifierRefCount.fetch_add(1) == 0) {
		std::lock_guard<priority_mutex> sync(notifierInterruptMutex);
		// create manager and alarm if not already created
		if (!notifierManager) {
			notifierManager = new tInterruptManager(1 << kTimerInterruptNumber, false, status);
			notifierManager->registerHandler(alarmCallback, NULL, status);
			notifierManager->enable(status);
		}
		if (!notifierAlarm) notifierAlarm = tAlarm::create(status);
	}

	std::lock_guard<priority_recursive_mutex> sync(notifierMutex);
	// create notifier structure and add to list
	Notifier* notifier = new Notifier();
	notifier->prev = nullptr;
	notifier->next = notifiers;
	if (notifier->next) notifier->next->prev = notifier;
	notifier->param = param;
	notifier->process = process;
	notifiers = notifier;
	return notifier;
}
开发者ID:FRCTeam159,项目名称:MentorRepository,代码行数:30,代码来源:Notifier.cpp

示例11: main

int main()
#endif
{
	gViewerThread = nullptr;
	gRunThread.clear();

	lua_State* L = luaL_newstate();
	luaL_openlibs(L);

	IupOpen(nullptr, nullptr);
	IupControlsOpen();
	iuplua_open(L);
	iupcontrolslua_open(L);

	TER::LoadFunctions(L);
	ZON::LoadFunctions(L);
	MOD::LoadFunctions(L);
	WLD::LoadFunctions(L);
	Viewer::LoadFunctions(L);
	Util::LoadFunctions(L);

	if (luaL_loadfile(L, "gui/main.lua") != 0)
	{
		ShowError("Could not load GUI script:\n%s\n", lua_tostring(L, -1));
	}
	else if (lua_pcall(L, 0, 0, 0) != 0)
	{
		ShowError("Runtime error:\n%s\n", lua_tostring(L, -1));
	}

	lua_close(L);
	return 0;
}
开发者ID:Xackery,项目名称:EQGZoneImporter,代码行数:33,代码来源:main.cpp

示例12: robotPoseCallback

void robotPoseCallback(const wrecs_msgs::sf_state_est::ConstPtr& msg)
{
	if (!lock.test_and_set()) {
		for (int i = 0; i < 30; i++) {
			stored_msg.Joints[i] = msg->joints[i];
		}

		for (int i = 0; i < 3; i++) {
			stored_msg.ComEst[i] = msg->com_est[i];
		}

		for (int i = 0; i < 2; i++) {
			stored_msg.CopEst[i] = msg->cop_est[i];
		}


		stored_msg.FootBF0.X = msg->foot_b_F[0].x;
		stored_msg.FootBF0.Y = msg->foot_b_F[0].y;
		stored_msg.FootBF0.Z = msg->foot_b_F[0].z;

		stored_msg.FootBF1.X = msg->foot_b_F[1].x;
		stored_msg.FootBF1.Y = msg->foot_b_F[1].y;
		stored_msg.FootBF1.Z = msg->foot_b_F[1].z;

		stored_msg.SdfMidFoot0.Position.X = msg->sdf_mid_foot[0].position.x;
		stored_msg.SdfMidFoot0.Position.Y = msg->sdf_mid_foot[0].position.y;
		stored_msg.SdfMidFoot0.Position.Z = msg->sdf_mid_foot[0].position.z;

		stored_msg.SdfMidFoot0.Orientation.W = msg->sdf_mid_foot[0].orientation.w;
		stored_msg.SdfMidFoot0.Orientation.X = msg->sdf_mid_foot[0].orientation.x;
		stored_msg.SdfMidFoot0.Orientation.Y = msg->sdf_mid_foot[0].orientation.y;
		stored_msg.SdfMidFoot0.Orientation.Z = msg->sdf_mid_foot[0].orientation.z;

		stored_msg.SdfMidFoot1.Position.X = msg->sdf_mid_foot[1].position.x;
		stored_msg.SdfMidFoot1.Position.Y = msg->sdf_mid_foot[1].position.y;
		stored_msg.SdfMidFoot1.Position.Z = msg->sdf_mid_foot[1].position.z;

		stored_msg.SdfMidFoot1.Orientation.W = msg->sdf_mid_foot[1].orientation.w;
		stored_msg.SdfMidFoot1.Orientation.X = msg->sdf_mid_foot[1].orientation.x;
		stored_msg.SdfMidFoot1.Orientation.Y = msg->sdf_mid_foot[1].orientation.y;
		stored_msg.SdfMidFoot1.Orientation.Z = msg->sdf_mid_foot[1].orientation.z;

        newMessageArrived = true;

		lock.clear();
	}
}
开发者ID:bnurbekov,项目名称:Humanoid_Robot_Learning_To_Walk,代码行数:47,代码来源:ROS_sub.cpp

示例13: lock

 void lock() {
     while (m_lock.test_and_set(std::memory_order_acquire)) {
         //spin 
     }
     // test_and_set, atomically sets the flag to true and obtains its previous value 
     // if value is false, set to true, return false, no spin, acquire lock.
     // if value is true, return true, spin... 
 }
开发者ID:renc,项目名称:coding_exercises,代码行数:8,代码来源:ex8_threadlock.cpp

示例14: main

int main()
{
    lock.test_and_set();
    std::thread t1(f,1);
    std::thread t2(g,2);

    t1.join();
    t2.join();
}
开发者ID:tomatolionz,项目名称:cplusplus,代码行数:9,代码来源:main.cpp

示例15: handleTimeout_

 /**
  * \param error The error that occured, if any.
  */
 void handleTimeout_(boost::system::error_code const & error) {
     if (!error) {
         std::cout << "Executing random behavior." << std::endl;
         if (!engine_.behavior.queued()) engine_.behavior.enqueueRandom(prefix);
         asyncWaitRandom_();
     } else {
         started_.clear();
     }
 }
开发者ID:jettan,项目名称:robotutor,代码行数:12,代码来源:pose_changer.cpp


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