Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #68355
| From | Ralf Fassel <ralfixx@gmx.de> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: std::thread - DESPERATE NEED HELP!!! |
| Date | 2019-09-12 11:14 +0200 |
| Message-ID | <ygah85h6fln.fsf@akutech.de> (permalink) |
| References | <NRaeF.332144$R83.166244@fx23.am4> |
* Szyk Cech <szykcech@spoko.pl>
| void Semaphore::down()
| {
| unique_lock lock(mAccessMutex);
| --mCounter;
| if(mCounter < 0)
| mWaitingCondition.wait(lock);
| }
Look up "spurious wakeups". IMHO it is better to use the predicate-form
of cv.wait() (#2 in https://en.cppreference.com/w/cpp/thread/condition_variable/wait)
| for(unsigned long i(0); i < lArray.size(); ++i)
| lArray[i] = thread(SemTestThread, &lSem);
>
| bool lResult(true);
>
| for(int i(0); i < 5; ++i)
| lArray[i].join();
There is no guarantee that the first five threads will *not* block in
sem->down(). Just that they are created first does not guarantee they
execute first. If lArray[5] executes before lArray[4], lArray[4].join()
will block since it still waits in sem->down().
R'
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
std::thread - DESPERATE NEED HELP!!! Szyk Cech <szykcech@spoko.pl> - 2019-09-11 20:16 +0200
Re: std::thread - DESPERATE NEED HELP!!! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-11 23:01 -0700
Re: std::thread - DESPERATE NEED HELP!!! Ralf Fassel <ralfixx@gmx.de> - 2019-09-12 11:14 +0200
Re: std::thread - DESPERATE NEED HELP!!! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-13 12:53 -0700
Re: std::thread - DESPERATE NEED HELP!!! Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2019-09-13 23:38 -0400
Re: std::thread - DESPERATE NEED HELP!!! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-13 22:07 -0700
Re: std::thread - DESPERATE NEED HELP!!! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-13 22:17 -0700
Re: std::thread - DESPERATE NEED HELP!!! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-13 23:01 -0700
csiph-web