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


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

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


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

示例1: StartDVDThread

namespace DVDThread
{
struct ReadRequest
{
  bool copy_to_ram;
  u32 output_address;
  u64 dvd_offset;
  u32 length;
  DiscIO::Partition partition;

  // This determines which code DVDInterface will run to reply
  // to the emulated software. We can't use callbacks,
  // because function pointers can't be stored in savestates.
  DVDInterface::ReplyType reply_type;

  // IDs are used to uniquely identify a request. They must not be
  // identical to IDs of any other requests that currently exist, but
  // it's fine to re-use IDs of requests that have existed in the past.
  u64 id;

  // Only used for logging
  u64 time_started_ticks;
  u64 realtime_started_us;
  u64 realtime_done_us;
};

using ReadResult = std::pair<ReadRequest, std::vector<u8>>;

static void StartDVDThread();
static void StopDVDThread();

static void DVDThread();
static void WaitUntilIdle();

static void StartReadInternal(bool copy_to_ram, u32 output_address, u64 dvd_offset, u32 length,
                              const DiscIO::Partition& partition,
                              DVDInterface::ReplyType reply_type, s64 ticks_until_completion);

static void FinishRead(u64 id, s64 cycles_late);
static CoreTiming::EventType* s_finish_read;

static u64 s_next_id = 0;

static std::thread s_dvd_thread;
static Common::Event s_request_queue_expanded;    // Is set by CPU thread
static Common::Event s_result_queue_expanded;     // Is set by DVD thread
static Common::Flag s_dvd_thread_exiting(false);  // Is set by CPU thread

static Common::SPSCQueue<ReadRequest, false> s_request_queue;
static Common::SPSCQueue<ReadResult, false> s_result_queue;
static std::map<u64, ReadResult> s_result_map;

static std::unique_ptr<DiscIO::Volume> s_disc;

void Start()
{
  s_finish_read = CoreTiming::RegisterEvent("FinishReadDVDThread", FinishRead);

  s_request_queue_expanded.Reset();
  s_result_queue_expanded.Reset();
  s_request_queue.Clear();
  s_result_queue.Clear();

  // This is reset on every launch for determinism, but it doesn't matter
  // much, because this will never get exposed to the emulated game.
  s_next_id = 0;

  StartDVDThread();
}

static void StartDVDThread()
{
  ASSERT(!s_dvd_thread.joinable());
  s_dvd_thread_exiting.Clear();
  s_dvd_thread = std::thread(DVDThread);
}

void Stop()
{
  StopDVDThread();
  s_disc.reset();
}

static void StopDVDThread()
{
  ASSERT(s_dvd_thread.joinable());

  // By setting s_DVD_thread_exiting, we ask the DVD thread to cleanly exit.
  // In case the request queue is empty, we need to set s_request_queue_expanded
  // so that the DVD thread will wake up and check s_DVD_thread_exiting.
  s_dvd_thread_exiting.Set();
  s_request_queue_expanded.Set();

  s_dvd_thread.join();
}

void DoState(PointerWrap& p)
{
  // By waiting for the DVD thread to be done working, we ensure
  // that s_request_queue will be empty and that the DVD thread
//.........这里部分代码省略.........
开发者ID:AdmiralCurtiss,项目名称:dolphin,代码行数:101,代码来源:DVDThread.cpp

示例2:

 ~scoped_thread()
 {
     t.join();
 }
开发者ID:AnnYN,项目名称:CCiA,代码行数:4,代码来源:listing_2.6.cpp

示例3: waitDone

void CBackupDeleter::waitDone()
{
	if (_thread.joinable())
		_thread.join();
}
开发者ID:almorel,项目名称:hubic-backup,代码行数:5,代码来源:main.cpp

示例4: join

	void join() { internal_thread.join(); }
开发者ID:DevStarSJ,项目名称:Study,代码行数:1,代码来源:ch.09.02.02.broken.interrupted_wait.cpp

示例5: Flush

void Flush()
{
	// If already saving state, wait for it to finish
	if (g_save_thread.joinable())
		g_save_thread.join();
}
开发者ID:BlackBeetleKing,项目名称:dolphin,代码行数:6,代码来源:State.cpp

示例6: defined

namespace State
{

#if defined(__LZO_STRICT_16BIT)
static const u32 IN_LEN = 8 * 1024u;
#elif defined(LZO_ARCH_I086) && !defined(LZO_HAVE_MM_HUGE_ARRAY)
static const u32 IN_LEN = 60 * 1024u;
#else
static const u32 IN_LEN = 128 * 1024u;
#endif

static const u32 OUT_LEN = IN_LEN + (IN_LEN / 16) + 64 + 3;

static unsigned char __LZO_MMODEL out[OUT_LEN];

#define HEAP_ALLOC(var, size) \
	lzo_align_t __LZO_MMODEL var[((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo_align_t)]

static HEAP_ALLOC(wrkmem, LZO1X_1_MEM_COMPRESS);

static std::string g_last_filename;

static CallbackFunc g_onAfterLoadCb = nullptr;

// Temporary undo state buffer
static std::vector<u8> g_undo_load_buffer;
static std::vector<u8> g_current_buffer;
static int g_loadDepth = 0;

static std::mutex g_cs_undo_load_buffer;
static std::mutex g_cs_current_buffer;
static Common::Event g_compressAndDumpStateSyncEvent;

static std::thread g_save_thread;

// Don't forget to increase this after doing changes on the savestate system
static const u32 STATE_VERSION = 43;	// Last changed in PR 2232

// Maps savestate versions to Dolphin versions.
// Versions after 42 don't need to be added to this list,
// beacuse they save the exact Dolphin version to savestates.
static const std::map<u32, std::pair<std::string, std::string>> s_old_versions =
{
	// The 16 -> 17 change modified the size of StateHeader,
	// so version older than that can't even be decompressed anymore
	{ 17, { "3.5-1311", "3.5-1364" } },
	{ 18, { "3.5-1366", "3.5-1371" } },
	{ 19, { "3.5-1372", "3.5-1408" } },
	{ 20, { "3.5-1409", "4.0-704" } },
	{ 21, { "4.0-705", "4.0-889" } },
	{ 22, { "4.0-905", "4.0-1871" } },
	{ 23, { "4.0-1873", "4.0-1900" } },
	{ 24, { "4.0-1902", "4.0-1919" } },
	{ 25, { "4.0-1921", "4.0-1936" } },
	{ 26, { "4.0-1939", "4.0-1959" } },
	{ 27, { "4.0-1961", "4.0-2018" } },
	{ 28, { "4.0-2020", "4.0-2291" } },
	{ 29, { "4.0-2293", "4.0-2360" } },
	{ 30, { "4.0-2362", "4.0-2628" } },
	{ 31, { "4.0-2632", "4.0-3331" } },
	{ 32, { "4.0-3334", "4.0-3340" } },
	{ 33, { "4.0-3342", "4.0-3373" } },
	{ 34, { "4.0-3376", "4.0-3402" } },
	{ 35, { "4.0-3409", "4.0-3603" } },
	{ 36, { "4.0-3610", "4.0-4480" } },
	{ 37, { "4.0-4484", "4.0-4943" } },
	{ 38, { "4.0-4963", "4.0-5267" } },
	{ 39, { "4.0-5279", "4.0-5525" } },
	{ 40, { "4.0-5531", "4.0-5809" } },
	{ 41, { "4.0-5811", "4.0-5923" } },
	{ 42, { "4.0-5925", "4.0-5946" } }
};

enum
{
	STATE_NONE = 0,
	STATE_SAVE = 1,
	STATE_LOAD = 2,
};

static bool g_use_compression = true;

void EnableCompression(bool compression)
{
	g_use_compression = compression;
}

static std::string DoState(PointerWrap& p)
{
	u32 version = STATE_VERSION;
	{
		static const u32 COOKIE_BASE = 0xBAADBABE;
		u32 cookie = version + COOKIE_BASE;
		p.Do(cookie);
		version = cookie - COOKIE_BASE;
	}

	std::string version_created_by = scm_rev_str;
	if (version > 42)
		p.Do(version_created_by);
//.........这里部分代码省略.........
开发者ID:BlackBeetleKing,项目名称:dolphin,代码行数:101,代码来源:State.cpp

示例7: EmuThreadJoin

static void EmuThreadJoin() {
	emuThread.join();
	emuThread = std::thread();
	ILOG("EmuThreadJoin - joined");
}
开发者ID:pal1000,项目名称:ppsspp,代码行数:5,代码来源:app-android.cpp

示例8: scoped_thread

 explicit scoped_thread(std::thread t_):
     t(std::move(t_))
 {
     if(!t.joinable())
         throw std::logic_error("No thread");
 }
开发者ID:AnnYN,项目名称:CCiA,代码行数:6,代码来源:listing_2.6.cpp

示例9: EmuThread

// Initialize and create emulation thread
// Call browser: Init():s_emu_thread().
// See the BootManager.cpp file description for a complete call schedule.
void EmuThread()
{
	const SConfig& core_parameter = SConfig::GetInstance();

	Common::SetCurrentThreadName("Emuthread - Starting");

	if (SConfig::GetInstance().m_OCEnable)
		DisplayMessage("WARNING: running at non-native CPU clock! Game may not be stable.", 8000);
	DisplayMessage(cpu_info.brand_string, 8000);
	DisplayMessage(cpu_info.Summarize(), 8000);
	DisplayMessage(core_parameter.m_strFilename, 3000);

	// For a time this acts as the CPU thread...
	DeclareAsCPUThread();

	Movie::Init();

	HW::Init();

	if (!g_video_backend->Initialize(s_window_handle))
	{
		PanicAlert("Failed to initialize video backend!");
		Host_Message(WM_USER_STOP);
		return;
	}

	OSD::AddMessage("Dolphin " + g_video_backend->GetName() + " Video Backend.", 5000);

	if (cpu_info.HTT)
		SConfig::GetInstance().bDSPThread = cpu_info.num_cores > 4;
	else
		SConfig::GetInstance().bDSPThread = cpu_info.num_cores > 2;

	if (!DSP::GetDSPEmulator()->Initialize(core_parameter.bWii, core_parameter.bDSPThread))
	{
		HW::Shutdown();
		g_video_backend->Shutdown();
		PanicAlert("Failed to initialize DSP emulation!");
		Host_Message(WM_USER_STOP);
		return;
	}

	bool init_controllers = false;
	if (!g_controller_interface.IsInit())
	{
		Pad::Initialize(s_window_handle);
		Keyboard::Initialize(s_window_handle);
		init_controllers = true;
	}
	else
	{
		// Update references in case controllers were refreshed
		Pad::LoadConfig();
		Keyboard::LoadConfig();
	}

	// Load and Init Wiimotes - only if we are booting in Wii mode
	if (core_parameter.bWii)
	{
		if (init_controllers)
			Wiimote::Initialize(s_window_handle, !s_state_filename.empty());
		else
			Wiimote::LoadConfig();

		// Activate Wiimotes which don't have source set to "None"
		for (unsigned int i = 0; i != MAX_BBMOTES; ++i)
			if (g_wiimote_sources[i])
				GetUsbPointer()->AccessWiiMote(i | 0x100)->Activate(true);

	}

	AudioCommon::InitSoundStream();

	// The hardware is initialized.
	s_hardware_initialized = true;

	// Boot to pause or not
	Core::SetState(core_parameter.bBootToPause ? Core::CORE_PAUSE : Core::CORE_RUN);

	// Load GCM/DOL/ELF whatever ... we boot with the interpreter core
	PowerPC::SetMode(PowerPC::MODE_INTERPRETER);

	CBoot::BootUp();

	// Thread is no longer acting as CPU Thread
	UndeclareAsCPUThread();

	// Setup our core, but can't use dynarec if we are compare server
	if (core_parameter.iCPUCore != PowerPC::CORE_INTERPRETER
	    && (!core_parameter.bRunCompareServer || core_parameter.bRunCompareClient))
	{
		PowerPC::SetMode(PowerPC::MODE_JIT);
	}
	else
	{
		PowerPC::SetMode(PowerPC::MODE_INTERPRETER);
	}
//.........这里部分代码省略.........
开发者ID:bullist,项目名称:dolphin,代码行数:101,代码来源:Core.cpp

示例10: Callback_WiimoteInterruptChannel

namespace Core
{

// TODO: ugly, remove
bool g_aspect_wide;

bool g_want_determinism;

// Declarations and definitions
static Common::Timer s_timer;
static std::atomic<u32> s_drawn_frame;
static std::atomic<u32> s_drawn_video;

// Function forwarding
void Callback_WiimoteInterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size);

// Function declarations
void EmuThread();

static bool s_is_stopping = false;
static bool s_hardware_initialized = false;
static bool s_is_started = false;
static void* s_window_handle = nullptr;
static std::string s_state_filename;
static std::thread s_emu_thread;
static StoppedCallbackFunc s_on_stopped_callback = nullptr;

static std::thread s_cpu_thread;
static bool s_request_refresh_info = false;
static int s_pause_and_lock_depth = 0;
static bool s_is_framelimiter_temp_disabled = false;

#ifdef ThreadLocalStorage
static ThreadLocalStorage bool tls_is_cpu_thread = false;
#else
static pthread_key_t s_tls_is_cpu_key;
static pthread_once_t s_cpu_key_is_init = PTHREAD_ONCE_INIT;
static void InitIsCPUKey()
{
	pthread_key_create(&s_tls_is_cpu_key, nullptr);
}
#endif

bool GetIsFramelimiterTempDisabled()
{
	return s_is_framelimiter_temp_disabled;
}

void SetIsFramelimiterTempDisabled(bool disable)
{
	s_is_framelimiter_temp_disabled = disable;
}

std::string GetStateFileName() { return s_state_filename; }
void SetStateFileName(const std::string& val) { s_state_filename = val; }

void FrameUpdateOnCPUThread()
{
	if (NetPlay::IsNetPlayRunning())
		NetPlayClient::SendTimeBase();
}

// Display messages and return values

// Formatted stop message
std::string StopMessage(bool main_thread, const std::string& message)
{
	return StringFromFormat("Stop [%s %i]\t%s\t%s",
		main_thread ? "Main Thread" : "Video Thread", Common::CurrentThreadId(), MemUsage().c_str(), message.c_str());
}

void DisplayMessage(const std::string& message, int time_in_ms)
{
	if (!IsRunning())
		return;

	// Actually displaying non-ASCII could cause things to go pear-shaped
	for (const char& c : message)
	{
		if (!std::isprint(c))
			return;
	}

	g_video_backend->Video_AddMessage(message, time_in_ms);
	Host_UpdateTitle(message);
}

bool IsRunning()
{
	return (GetState() != CORE_UNINITIALIZED || s_hardware_initialized) && !s_is_stopping;
}

bool IsRunningAndStarted()
{
	return s_is_started && !s_is_stopping;
}

bool IsRunningInCurrentThread()
{
	return IsRunning() && IsCPUThread();
//.........这里部分代码省略.........
开发者ID:bullist,项目名称:dolphin,代码行数:101,代码来源:Core.cpp

示例11: LogicError

 ~LedgerCleanerImp () override
 {
     if (thread_.joinable())
         LogicError ("LedgerCleanerImp::onStop not called.");
 }
开发者ID:blockc,项目名称:rippled,代码行数:5,代码来源:LedgerCleaner.cpp

示例12: assert

void CBackupDeleter::start()
{
	assert(!_thread.joinable());
	_thread= std::thread( &CBackupDeleter::run, this);
}
开发者ID:almorel,项目名称:hubic-backup,代码行数:5,代码来源:main.cpp

示例13:

 void 
 GroupNodeImpl::join()    
 {    
   event_thread_->join();    
 }
开发者ID:mikegulf,项目名称:quickmsg,代码行数:5,代码来源:group_node.cpp

示例14: join

void join(std::thread &t)
{
  t.join();
}
开发者ID:lhz92,项目名称:SungemSDK-ROS,代码行数:4,代码来源:hs_manager.cpp

示例15: detach

	void detach() { internal_thread.detach(); }
开发者ID:DevStarSJ,项目名称:Study,代码行数:1,代码来源:ch.09.02.02.broken.interrupted_wait.cpp


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