C++并发编程练习06 “线程管理之线程对象转移“

2023-05-16

线程对象可以和一般对象一样,其所有权可以被转移,示例如下:

#include <iostream>
#include <thread>

void get(std::thread&& t)
{
	t.detach();
	int a;
	std::cin >> a;
	std::cout << a << std::endl;
}

void task(const char* sz)
{
	std::cout << sz << std::endl;
}

int main()
{
	std::thread th(task, "i come from there!");
	get(std::move(th));

	return 0;
}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

C++并发编程练习06 “线程管理之线程对象转移“ 的相关文章

  • vim常用指令类表

    最近开始Linux环境下编程 xff0c 有时需要使用vim浏览和修改代码 xff0c 特意学习了一下 xff0c 并整理了一些常用指令 xff0c 如下所示 VIM常用命令 工作模式 正常模式 Esc编辑模式 i可视选择模式 v文件 打开
  • 2021-06-23

    root 64 localhost cat usr share applications Lxg desktop Desktop Entry Name 61 Lxg Type 61 Application Exec 61 home lys
  • gcc编译过程

    1 下载相应代码库 xff0c 解压到一个大的文件夹的各子文件夹 2 执行脚本 cd gmp 5 0 0 make clean configure disable shared enable static prefix 61 usr loc
  • 【vscode】去除黄色波浪下划线

    vscode 去除黄色波浪下划线 vscode在使用过程中 xff0c 如果出现变量名下方出现黄色波浪线 xff0c 影响编程效率 可能原因是由于安装了pylint这个库 xff0c 并没有进行合适的设置 我们可以在设置中查找 34 pyt
  • Volume 多边形裁剪测试

    vtk自带了一个Volume剪切的例子 xff0c 可以用隐函数确定的剪切面裁剪vtkImageData 本人对该例子代码略加修改 xff0c 剪切口为一个封闭的梯形 其代码和配置文件如下 目录 ClipVolume cxx CMakeLi
  • VTK应用程序连接出现vtkRenderingOpenGL_AutoInit_Construct(void)报错解决方法一则

    出现vtkRenderingOpenGL AutoInit Construct void 报错 xff1a xff08 1 xff09 具体报错为 xff1a error LNK2019 无法解析的外部符号 34 void cdecl vt
  • 在Debian下安装输入法的过程

    执行下面的命令 xff1a sudo apt get install software properties common apt add repository ppa fcitx team nightly sudo apt get upd
  • 【MITK】在Windows中编译MITK

    1 在Git Bash执行下面的命令 cd D mkdir MITK cd MITK git clone https phabricator mitk org source mitk git MITK cd MITK cmake S B W
  • 解决WSL中Debian显示中文乱码的问题

    1 sudo apt get install locales 2 sudo dpkg reconfigure locales 勾选 zh CN XX 3 sudo locale gen 4 sudo apt get install ttf
  • WSL中Debian配置中文输入法

    1 sudo apt install dbus x11 im config fonts noto fcitx fcitx pinyin fcitx sunpinyin fcitx googlepinyin 2 fcitx autostart
  • Windows 下获得当前线程上下文并保存到dump文件测试之2

    include lt Windows h gt include lt Dbghelp h gt include lt excpt h gt include lt exception gt include lt iostream gt inc
  • 使用函数钩子实现打印throw异常时的调用栈

    include lt Windows h gt include lt winnt h gt include lt Dbghelp h gt include lt excpt h gt include lt ehdata h gt inclu
  • MFC/QT混合编程时使用QMessageBox一例

    MFC QT混合编程的方法可以参考这个链接 xff1a MFC QT混合编程官方方法 1 使用QMessageBox可以这样 xff1a void CJxDicomerApp OnTest QWinWidget parent 61 new
  • C++流编程学习例子01

    C 43 43 流有一个类继承体制 xff0c 符合C 43 43 类的语义 下面的代码使用std cout作为std ostream引用 xff0c 能够正确输出信息 我们也可以用ofstream ostringstream等做类似操作
  • 洛谷P1593 因子和

    题目描述 输入两个正整数a和b xff0c 求a b的因子和 结果太大 xff0c 只要输出它对9901的余数 输入输出格式 输入格式 xff1a 仅一行 xff0c 为两个正整数a和b 0 a b 50000000 输出格式 xff1a
  • android layout view 编辑器

    DroidDraw is a graphical user interface GUI builder for the Android platform 下载地址 xff1a http code google com p droiddraw
  • new[]和new调用地址的简单跟踪

    重写这两个操作符 xff0c 插入打印语句 xff0c 可获得调用地址 代码如下 xff1a include lt Windows h gt include lt iostream gt include lt stdlib h gt inc
  • C++使用new 和new[]操作符分配内存时的调用栈跟踪显示2

    我们可以通过这个技术分析内存泄漏的调用函数和位置 include lt Windows h gt include lt ImageHlp h gt include lt iostream gt include lt string gt in
  • 使用信号机制在Linux程序中打印函数调用栈

    include lt stdio h gt include lt stdlib h gt include lt signal h gt include lt execinfo h gt include lt ucontext h gt vo
  • 在OpenEuler上安装Redmine

    在openeuler上安装Linux xff0c Apache xff0c MariaDB xff0c PHP xff08 LAMP xff09 堆栈 快速入门 转载 先决条件 需要以sudo用户身份访问openeuler服务器 第1步 安

随机推荐