首页 > 其他分享 >测试SuspendThread、ResumeThread

测试SuspendThread、ResumeThread

时间:2024-01-10 15:14:56浏览次数:28  
标签:case SuspendThread ResumeThread int break static 测试 NULL EVT

#include <iostream>
#include <windows.h>
#include <process.h>
#include <conio.h>

enum {
	EVT_PAUSE = 0,
	EVT_RESUME,
	EVT_QUIT,
	EVT_TOTAL
};
static HANDLE events[EVT_TOTAL] = { NULL,NULL,NULL };

static unsigned int  __stdcall helper_thread_proc(void * para)
{
	int key;
	bool quit = false;
	do {
		key = _getch();
		switch (key) {
		case 'q':
		case 'Q':
			SetEvent(events[EVT_PAUSE]);
			break;
		case 'w':
		case 'W':
			SetEvent(events[EVT_RESUME]);
			break;
		case 'e':
		case 'E':
			quit = true;
			SetEvent(events[EVT_QUIT]);
			break;
		default:
			break;
		}
		if(quit)
			break;
	} while (1);

	return 0;
}

static HANDLE start_helper_thread()
{
	HANDLE hdl;
	hdl = (HANDLE)_beginthreadex(NULL, 0, helper_thread_proc, NULL, 0, NULL);
	return hdl;
}

static unsigned int _stdcall result_monitor_thread(void* para)
{
	unsigned int i = 1;

	while (1)
	{
		std::cout << i << std::endl;
		++i;
	}
		
	return 0;
}
static HANDLE start_monitor_thread()
{
	HANDLE hdl;
	hdl = (HANDLE)_beginthreadex(NULL, 0, result_monitor_thread, NULL, 0, NULL);
	return hdl;
}

int main()
{
	HANDLE hdl = start_monitor_thread();
	if (hdl == NULL) {
		printf("create monitor thread failed\n");
	}

	HANDLE helper_thread = start_helper_thread();
	if (helper_thread == NULL) {
		printf("create helper thread failed\n");
	}
	DWORD waitres;
	for (int i = 0; i < EVT_TOTAL; ++i) {
		events[i] = CreateEvent(NULL, FALSE, FALSE, NULL);
	}
	bool quit = false;
	while(1)
	{
		waitres = WaitForMultipleObjects(EVT_TOTAL, events, FALSE, INFINITE);
		switch (waitres)
		{
		case WAIT_OBJECT_0 + EVT_PAUSE:
			SuspendThread(hdl);
			break;
		case WAIT_OBJECT_0 + EVT_RESUME:
			ResumeThread(hdl);
			break;
		case WAIT_OBJECT_0 + EVT_QUIT:
			quit = true;
			break;
		default:
			break;
		}
		if (quit)
			break;
	}

	if (hdl != NULL)
	{
		CloseHandle(hdl);
	}
	if (helper_thread != NULL) {
		WaitForSingleObject(helper_thread, INFINITE);
		CloseHandle(helper_thread);
	}

	return 0;
}

标签:case,SuspendThread,ResumeThread,int,break,static,测试,NULL,EVT
From: https://www.cnblogs.com/horizonhz/p/17956494

相关文章

  • Cognex 的 CogFitCircle 和 CogNPointToNPoint 类的简单测试
    privatevoidbtn_Test_Click(objectsender,RoutedEventArgse){CogFitCirclecogFitCircle=newCogFitCircle();cogFitCircle.AddPoint(0,10);cogFitCircle.AddPoint(10,0);cogFitCircle.AddPoint(0,-10);cogFitCircle.AddPoint(-10,0);......
  • Windows桌面自动化测试工具:WinAppDriver
    大家好,今天给大家介绍一款Windows桌面自动化测试工具:WinAppDriver。1、介绍WinAppDriver是一个开源的自动化测试工具,用于测试Windows应用程序。它是一个WindowsApplicationDriver,可以与多种自动化测试框架和工具集成,如Selenium、Appium等。WinAppDriver提供了一组API,用于与Win......
  • 使用cURL命令在Linux中测试HTTP服务器的性能
    cURL是一个强大的命令行工具,用于从或向服务器传输数据。它支持多种协议,包括HTTP、HTTPS、FTP等。在Linux系统中,cURL可以用于测试和评估HTTP服务器的性能。下面是一些使用cURL命令测试HTTP服务器性能的示例和说明。1.基本请求要向指定的URL发送基本的GET请求,你可以使用以下命令:bash......
  • trwebocr性能测试
    OCR版本:trwebocr:1.0.4运行方式:CPU机器配置:1C,16G样本文件:xxxxx.png(原文件)线程组样本平均值(ms)最小值(ms)最大值(ms)标准偏差(ms)异常吞吐量(sec)接收KB/sec发送KB/sec平均字节数CPU使用情况线程数:50,时间:100,循环次数:15010789578451973655352......
  • test-01-java 单元测试框架 junit 入门介绍
    拓展阅读junit5系列基于junit5实现junitperf源码分析Autogeneratemockdataforjavatest.(便于Java测试自动生成对象信息)Junitperformancerelyonjunit5andjdk8+.(java性能测试框架。性能测试。压测。测试报告生成。)JUnitJUnit是一个用于编写可重复测试......
  • test-02-java 单元测试框架 junit5 入门介绍
    拓展阅读junit5系列基于junit5实现junitperf源码分析Autogeneratemockdataforjavatest.(便于Java测试自动生成对象信息)Junitperformancerelyonjunit5andjdk8+.(java性能测试框架。性能测试。压测。测试报告生成。)junit5的入门例子maven引入<depend......
  • 【Application Insights】使用Powershell命令向Application Insgihts发送测试数据
    问题描述在昨天的文章中,介绍了“【ApplicationInsights】使用CURL命令向ApplicationInsgihts发送测试数据 ”,今天则继续实验通过PowerShell命令来发送测试数据到ApplicationInsights 问题解答从参考文档中复制出Powershell脚本,然后只需要修改ApplicationInsights的Connect......
  • 软件测试/测试开发/全日制|Pytest测试用例调度与运行
    前言Pytest是一个功能强大的Python测试框架,它具有灵活的测试用例调度和运行机制。在本文中,我们将深入了解Pytest是如何收集、选取和运行测试用例的。测试用例的收集在Pytest中,测试用例是通过函数来表示的。为了进行测试,Pytest需要收集这些测试函数。默认情况下,Pytest会在......
  • 软件测试/人工智能/全日制测试开发|利用ChatGPT自动生成自动化测试脚本
    自动化测试是软件测试过程中不可或缺的一部分,它能够提高测试效率,减少测试成本,保障软件质量。然而,编写和维护自动化测试脚本仍然是一个具有挑战性的任务,需要花费大量的时间和精力。学会借助ChatGPT自动生成自动化测试脚本,就可以减少编写自动化脚本的工作量,提高测试效率。如何借助Cha......
  • 软件测试计划
    ......