Category : multithreading

I have an application that catalogs image files on my computer. In CWinApp::InitInstance, I initialize Gdiplus using the following: GdiplusStartupInput gdiplusStartupInput; GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL); also, in the init function of my library class, I do the same. Finally, because I spawn a separate thread to perform this task, I initialize GDI+ again at the beginning ..

Read more

So I want to wait until ender has started waiting here is what basically: std::condition_variable avalanche; std::mutex mutex; std::cout << "avalanche" << std::endl; std::thread ender{[&]{ std::unique_lock lock{mutex}; avalanche.wait(lock); }}; //Here how to wait until ender has started waiting on the //Conditional Variable I just can’t wrap my head around it. My goal ultimately is to ..

Read more

I’m making a version of the producer-consumer problem in C++20. I need to work on a number of buffers, each having their own threads of producers and consumers, the number of threads being an argument. Seeing as the number of threads isn’t a constant, I decided to store the threads in a vector, while the ..

Read more

I’ve been hearing so many conflicting answers, and now I don’t know what to think. The agreed-upon knowledge is that for sharing memory in a thread safe manner in C++, it’s required to use volatile together with std::mutex. Based on that understanding, I’ve been writing code like this: volatile bool ready = false; std::condition_variable cv; ..

Read more

I have this class: class abstracts{ public: // abstracts(string param){ // name = param; // } string name; set<string> allwords; vector<set<string> > sentences; vector<string> words; float Jaccard; }; and this function: void *func(void *param) { string item = *(string *) param; abstracts temp; temp.name = item; ifstream input; // open the abstract.txt input.open(item); vector<string> sentences; ..

Read more