I have the following code:
somefunc(string s, semaphore* sem) {
//some functionality
sem->signal();
}
int main() {
int num = 0;
semaphore sem(0);
vector<string> arr;
for (string& s : arr) {
++num;
thread(somefunc, s, &sem).detach();
}
for (int i = 0; i < num; i++)
sem.wait();
}
I am getting std::string allocation memory errors on the line where thread() is. Is there something wrong with this code? semaphore is a custom class that uses a mutex and a conditional variable.
Aucun commentaire:
Enregistrer un commentaire