首页 > 编程语言 >c++11 std::thread 线程实例在退出后管理线程调用join()后再新建线程将可能会产生相同std::thread::id的实例

c++11 std::thread 线程实例在退出后管理线程调用join()后再新建线程将可能会产生相同std::thread::id的实例

时间:2023-03-28 17:47:42浏览次数:30  
标签:std info vthread thread 54.372 线程 id

[03-28 16:52:54.372] [info] [vthread.cpp:92 operator()()] create new thread,id:4,tid:7f5cbb7fd640,inroduce:test vthread 003
[03-28 16:52:54.372] [info] [vthread.cpp:233 log()] 1/4 id:1 thread id:0x7f5cbc7ff640,create time:, status:2=running, introduce:"vthread manager"
[03-28 16:52:54.372] [info] [vthread.cpp:233 log()] 2/4 id:2 thread id:0x7f5cbbffe640,create time:, status:3=exit, introduce:"test vthread 002"
[03-28 16:52:54.372] [info] [vthread.cpp:233 log()] 3/4 id:3 thread id:0x7f5cbb7fd640,create time:, status:3=exit, introduce:"test vthread 003"
[03-28 16:52:54.372] [info] [vthread.cpp:233 log()] 4/4 id:4 thread id:0x7f5cbb7fd640,create time:, status:3=exit, introduce:"test vthread 003"
[03-28 16:52:54.372] [info] [vthread.cpp:233 log()] 1/4 id:1 thread id:0x7f5cbc7ff640,create time:, status:2=running, introduce:"vthread manager"
[03-28 16:52:54.372] [info] [vthread.cpp:233 log()] 2/4 id:2 thread id:0x7f5cbbffe640,create time:, status:3=exit, introduce:"test vthread 002"
[03-28 16:52:54.372] [info] [vthread.cpp:233 log()] 3/4 id:3 thread id:0x7f5cbb7fd640,create time:, status:3=exit, introduce:"test vthread 003"
[03-28 16:52:54.372] [info] [vthread.cpp:233 log()] 4/4 id:4 thread id:0x7f5cbb7fd640,create time:, status:3=exit, introduce:"test vthread 003"

 

c++11 std::thread 线程实例在退出后管理线程调用join()后再新建线程将可能会产生相同std::thread::id的实例,这个新线程实例是复用的之前join()释放掉线程实例的旧ID。

所以在用户程序中仅使用std::thread::id 作为线程管理的唯一标识是不够的,往往会导致程序逻辑上错误。

标签:std,info,vthread,thread,54.372,线程,id
From: https://www.cnblogs.com/colin-vio/p/17266092.html

相关文章

  • 【面试专栏】Java创建多线程的五种方式
    1.继承Thread类importlombok.extern.slf4j.Slf4j;importorg.junit.jupiter.api.Test;/***继承Thread类创建多线程单元测试**@authorCL*/@Slf4jpublic......
  • 一直报错Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.j
    按照网上的提示在pom.xml添加了依赖<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.11</version></depen......
  • 什么是线程死锁
    死锁是指两个或两个以上的进程(线程)在执行过程中,由于竞争资源或者由于彼此通信而造成的一种阻塞的现象,若无外力作用,它们都将无法推进下去。此时称系统处于死锁状态或系统产......
  • 线程的 run()和 start()有什么区别?
    每个线程都是通过某个特定Thread对象所对应的方法run()来完成其操作的,run()方法称为线程体。通过调用Thread类的start()方法来启动一个线程。start()方法用于启动线程,run......
  • 守护线程和用户线程有什么区别呢?
    在 Java中通常有两种线程:守护线程(DaemonThread)和用户线程(UserThread)。守护线程:是一种特殊的线程,在后台默默地完成一些系统性的服务,比如垃圾回收线程、JIT 线程都是......
  • python apscheduler 定时任务的基本使用-8-线程执行器ThreadPoolExecutor
    pythonapscheduler定时任务的基本使用-8-线程执行器ThreadPoolExecutor1、线程执行器ThreadPoolExecutor先说个人总结假设启动线程数为N,任务数为M,misfire_grace_tim......
  • C#:多线程操作Dictionary
    为了在多线程环境下操作Dictionary,我们需要确保线程安全。其中一种实现方式是使用ConcurrentDictionary类,该类位于System.Collections.Concurrent命名空间中。Concurrent......
  • linux内核线程优先级配置
    linux内核线程优先级配置/*referencedriver/spi/spi.c*/#include<linux/sched/rt.h>#include<uapi/linux/sched/types.h>staticstructsched_paramparam={......
  • 线程池
    1、线程池出现原因以前写多线程时,用到线程的时候就创建(浪费时间);用完之后线程就消失(浪费资源)。2、线程池主要核心原理  3、线程池代码实现(1)创建线程池(2)提交任务(3)......
  • 多线程 wait() notify的用法
    main类 packageendual;publicclassMainApp{ publicstaticvoidmain(String[]args){ Queryq=newQuery(0); Threadthread=newThread(newThrea......