Questions tagged [stdthread]

std::thread is a C++11 standard library class which represents a single thread of execution. Threads allow multiple functions to execute concurrently.

std::thread is a C++11 standard library type which creates a new thread and runs a function (or other callable object) in that new thread.

Include the <thread> header to use std::thread.

C++20 added std::jthread which automatically .join()s the thread on destruction instead of std::terminate()ing, a generally preferable behavior.

593 questions
0
votes
1 answer

std::thread on OpenCV function generates error "Attempt to use a deleted function"

This is the code I'm using: cv::Mat mask, foreground; std::thread t(cv::threshold, mask, foreground, 254, 255, cv::THRESH_BINARY); t.join(); Compiling with Xcode 8 with support for C++11. Any ideas? Here is the full error message: In file included…
Michael Litvin
  • 3,976
  • 1
  • 34
  • 40
0
votes
1 answer

Problems with a vector of std::threads in C++11 counting bigrams of letters and words

I am trying to implement a concurrent program to count occurrences of bigrams of words and letters in text files. The core are the two functions that calculate the bigrams. In the main I start threads with one of the two functions. There is a main…
0
votes
1 answer

How to safely remove std::thread in ATL DLL

I wrote an ATL DLL and I have problem with std::thread witch I used to run asyn method. I implemented method that performs operations asynchronously. The problem occurs when a client tries to remove the object class in which thread already…
Kuba
  • 39
  • 1
  • 6
0
votes
2 answers

Using and joining a std::thread object from different threads

This is a minimal example based on a code that was handed to me: // Example program #include #include #include int main() { std::cout << "Start main\n"; int i = 0; auto some_thread = std::thread([&]() { …
FranMowinckel
  • 4,233
  • 1
  • 30
  • 26
0
votes
0 answers

Why is join not executed by default

I'm wondering why is join() not done by default on the thread in all cases when we do not explicit detach thread? Wouldn't it spare lots of trouble and avoid joining treads where exception could happen or programmer just forget about it?
Mateusz Wojtczak
  • 1,621
  • 1
  • 12
  • 28
0
votes
1 answer

How to use PAPI with C++11 std:thread?

I would like to use PAPI to get the overall counters of all C++11 std::thread threads in a program. PAPI documentation on Threads says that: Thread support in the PAPI library can be initialized by calling the following low-level function in C:…
Nicola
  • 395
  • 2
  • 13
0
votes
1 answer

std::thread member function. Should class fields be accessed by this pointer?

Given a class such as: class MyClass { private: vector data; void threadWork(std::vector *data_ptr) { // some thread work... e.g for(int i=0; i < data_ptr->size(); i++) { std::string next =…
izaak_pyzaak
  • 930
  • 8
  • 23
0
votes
1 answer

Passing pointer as argument with std::thread function C++11

I wanted to pass a pointer to the thread function, but it gives back error: attempt to use a deleted function __invoke(_VSTD::move(_VSTD::get<0>(__t)), _VSTD::move(_VSTD::get<_In... Code fragment in main for (int i = 0; i <…
rpl
  • 33
  • 1
  • 6
0
votes
1 answer

std::thread pass vector element by reference

I'm trying to figure out why the following works: threaded thr[8] = { threaded(), threaded() ,threaded() ,threaded() ,threaded() ,threaded() ,threaded() ,threaded() }; std::vector vec; for (int i = 0; i < threads; i++) { …
lightxbulb
  • 1,251
  • 12
  • 29
0
votes
0 answers

Parallel optimization - multithreading performance hit

I want to run several runs of simulated annealing with different parameters many times to tune the parameters. It seemed like this would be an obvious use case for multiple threads since each run might take several seconds for a large number of…
0
votes
1 answer

Subclassing std::thread and forwarding packed/variadic template parameters

In my code I would like to have all threads subclass from a type that in turn subclasses from std::thread. The reasons, which I'm sure are common: A stop request from outside the thread, and continue check from inside the thread, are done the same…
jorgander
  • 540
  • 1
  • 4
  • 12
0
votes
1 answer

Sending jobs to a std::thread

I am quite new to std::thread and I quickly realized that creating them is quite costly at least on my computer running W7. So I decided to create my threads and send jobs to it using that piece of sample code:…
0
votes
1 answer

Usage threads in google tests

I want to create some tests to check multi-threading in my application. I use google test framework. My following code is not compiled with error message error: invalid use of non-static member function TEST_F( tc, t ) { std::thread thread1 ( f1,…
zubactik
  • 1,297
  • 3
  • 19
  • 34
0
votes
1 answer

Program terminating after FCGX_InitRequest() call

I have something like this: ... int fcgiInit = FCGX_Init(); if(fcgiInit != 0) { return 1; } int socket = FCGX_OpenSocket(":8000", 100); if(socket == -1) { return 2; } //point A FCGX_Request* request = new…
ktoś tam
  • 739
  • 1
  • 6
  • 11
0
votes
1 answer

Segmentation fault at std::thread

typedef struct _ppm_struct* ppm_struct; typedef unsigned char ppm_subpixel; typedef ppm_subpixel (*ppm_pixel_func)(ppm_subpixel); struct ppm_pixel { ppm_subpixel red; ppm_subpixel green; ppm_subpixel blue; }; struct _ppm_struct { …
MSD561
  • 512
  • 5
  • 16