stdthread Questions
1
For a better understanding of this question, here is the code:
// code 1
#include <iostream>
#include <thread>
struct tls_test {
tls_test()
{ std::cout << "tls_test ctor\n...
Thanasi asked 25/6, 2023 at 2:39
2
Consider the following two snippets of code where I am trying to launch 10000 threads:
Snippet 1
std::array<std::future<void>, 10000> furArr_;
try
{
size_t index = 0;
for (auto &...
Sales asked 22/6, 2017 at 2:24
5
Solved
I'm asking about the <thread> library in C++11 standard.
Say you have a function like:
void func1(int a, int b, ObjA c, ObjB d){
//blahblah implementation
}
int main(int argc, char* argv[])...
Stabilize asked 3/12, 2013 at 0:46
1
Solved
#include <iostream>
#include <thread>
template<int Num>
class MyClass {
public:
MyClass(int val) : val_(val) {}
// Copy constructor
MyClass(const MyClass& other) : val_(o...
Hittel asked 26/4, 2024 at 6:54
3
Solved
From my experience, it seems that the result of
std::this_thread::get_id()
is unique across process: ids are different from one process to another.
Is this guaranteed by the standard?
13
Solved
c++11 has a possibility of getting current thread id, but it is not castable to integer type:
cout<<std::this_thread::get_id()<<endl;
output : 139918771783456
cout<<(uint64_t)...
Fee asked 15/9, 2011 at 14:0
1
I'm testing edge cases with std::condition_variable and I tested scenario to starve one thread.
Scenario is that there are 99 producers and only one consumer, all of them working on 1 queue with ma...
Steatopygia asked 10/11, 2023 at 8:59
3
Solved
I am new to std::thread. I need to put a std::thread to sleep from another thread, is that possible? In examples, all I see is code like:
std::this_thread::sleep_for(std::chrono::seconds(1));
But ...
Emergent asked 12/10, 2012 at 12:55
0
I just got a juicy race condition. Consider the following classes:
#include <atomic>
#include <chrono>
#include <iostream>
#include <thread>
class A
{
std::thread th;
std...
Bomar asked 22/9, 2023 at 14:7
2
Solved
Quoting from The C++ Programming Language (by Bjarne Stroustrup), page 1213
The thread constructors are variadic templates (§28.6). This implies that to pass a reference to a
thread constructor, w...
9
Solved
How can I check if a std::thread is still running (in a platform independent way)?
It lacks a timed_join() method and joinable() is not meant for that.
I thought of locking a mutex with a std::loc...
Warily asked 1/2, 2012 at 10:41
2
Solved
Capturing a thread_local in a lambda:
#include <iostream>
#include <thread>
#include <string>
struct Person
{
std::string name;
};
int main()
{
thread_local Person user{"...
Urga asked 13/6, 2023 at 12:39
12
Relevant questions:
About C++11:
C++11: std::thread pooled?
Will async(launch::async) in C++11 make thread pools obsolete for avoiding expensive thread creation?
About Boost:
C++ boost threa...
Rusk asked 1/4, 2013 at 21:59
2
Solved
I'm confused how std::jthread::get_stop_token is designed to work, because it seems to have an inherent race condition.
Namely, the executing thread can't simply call std::jthread on itself (as in ...
Donovan asked 22/4, 2021 at 8:5
3
Solved
I have access to a std::thread::id in my code, and need to use some native functions that receive as argument ThreadId as DWORD ( same as returned by GetCurrentThreadId() ).
I cannot find any way...
Initiate asked 26/4, 2016 at 13:5
6
What is the correct way in the post C++11 world for setting the priority of an instance of std::thread?
Is there a portable way of doing this that works at least in Windows and POSIX (Linux) enviro...
Rollway asked 19/9, 2013 at 0:33
6
Solved
Sometime I have to use std::thread to speed up my application. I also know join() waits until a thread completes. This is easy to understand, but what's the difference between calling detach() and ...
7
Solved
Assume I'm starting a std::thread and then detach() it, so the thread continues executing even though the std::thread that once represented it, goes out of scope.
Assume further that the program d...
Dolliedolloff asked 2/11, 2013 at 16:43
5
Solved
In the following code snippet,
void foo() {
std::this_thread::native_handle().... //error here
}
int main() {
std::thread t1(foo);
t1.join();
return 0;
}
How do you get the native_handle f...
4
Solved
Why can't you pass an object by reference when creating a std::thread ?
For example the following snippit gives a compile error:
#include <iostream>
#include <thread>
using namespace...
Exorcism asked 3/12, 2015 at 23:25
4
Solved
My aim is to keep an std::thread object as data member, and initialize it when needed.
I'm not able to do this (as in my code below) because the copy constructor of the std::thread class is deleted...
Brahms asked 22/8, 2013 at 9:6
2
Solved
I'm trying to run a function called dcp in a thread, I've to run this function three times independently. So here's how I'm implemented that:
void dcp(cv::Mat&, int, int, cv::Mat&, double)...
Jerilynjeritah asked 13/5, 2018 at 14:53
1
In below code I could not understand why move constructor of class is called twice considering that my thread function is taking argument by rvalue reference and so I was hoping move construc...
Intertwist asked 16/5, 2018 at 5:11
2
Solved
Consider this program that essentially creates std::thread that calls the function func() with arg as argument:
#include <thread>
#include <iostream>
struct foo {
foo() = default;
...
1
In probing the conditions of this question, a problem arose, exemplified by the code below.
#include <iostream>
#include <thread>
#include <chrono>
#include <stdexcept>
#in...
1 Next >
© 2022 - 2025 — McMap. All rights reserved.