Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming.threads > #125
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!news.tornevall.net!news2.arglkargh.de!feeder.erje.net!news-hub.siol.net!newsfeed1.eu.ignite.net!news.cesnet.cz!news.felk.cvut.cz!not-for-mail |
|---|---|
| From | Vaclav Haisman <v.haisman@sh.cvut.cz> |
| Newsgroups | comp.programming.threads |
| Subject | Re: pthread question |
| Date | Mon, 09 May 2011 07:11:42 +0200 |
| Organization | Czech Technical University |
| Lines | 36 |
| Message-ID | <4DC7778E.8090707@sh.cvut.cz> (permalink) |
| References | <b3bf253c-0285-4eeb-8d64-e01fa16c5f0c@f15g2000pro.googlegroups.com> |
| NNTP-Posting-Host | 212.6.broadband3.iol.cz |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 7bit |
| X-Trace | ns.felk.cvut.cz 1304917902 91564 85.70.6.212 (9 May 2011 05:11:42 GMT) |
| X-Complaints-To | usenet@news.felk.cvut.cz |
| NNTP-Posting-Date | Mon, 9 May 2011 05:11:42 +0000 (UTC) |
| User-Agent | Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 |
| In-Reply-To | <b3bf253c-0285-4eeb-8d64-e01fa16c5f0c@f15g2000pro.googlegroups.com> |
| X-Enigmail-Version | 1.1.1 |
| Xref | x330-a1.tempe.blueboxinc.net comp.programming.threads:125 |
Show key headers only | View raw
p6 c6d6 wrote, On 9.5.2011 6:28:
> can pthread_func_1() eat up 100% cpu.
> i have the following scenario where pthread_fuc_1()
> is waiting on some global variable to be set.
> while pthread_func_2() does the setting of the global
> variable once it finsishes it's busy work.
> pthread_func_2() might wait on condition_variable while
> it is doing the work. In this scenario i've observed that
> my process is taking 100% cpu so i forced manual core
> on analyzing the core i've observed that pthread_func_1()
> thread is in Rnning state, pthread_func_2() is in cond_wait
> state. i was wondering, why pthread_func_1() is taking 100%
> cpu though there is pthread_yield(). i am guessing that
> it is reponsible for 100% cpu as it is the only thread in
> the running state, when forced it to coredump.
>
> pthread_func_1() {
> while (condition_not_met) {
> pthread_yield();
Even with pthread_yeield() it is busy waiting. You are correct about why,
despite the yield, it runs all the time. Change it to use conditional
variable as the pthread_func_2() does to avoid that.
> }
> }
>
> pthread_func_2() {
> while (there is busy work) {
> doing some busy work;
> wait on some condition var;
> }
> condition_not_met = 0;
> }
--
VH
Back to comp.programming.threads | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
pthread question p6 c6d6 <p6c6d6@gmail.com> - 2011-05-08 21:28 -0700
Re: pthread question Vaclav Haisman <v.haisman@sh.cvut.cz> - 2011-05-09 07:11 +0200
Re: pthread question Joshua Maurice <joshuamaurice@gmail.com> - 2011-05-09 11:49 -0700
Re: pthread question David Schwartz <davids@webmaster.com> - 2011-05-09 12:24 -0700
Re: pthread question Joshua Maurice <joshuamaurice@gmail.com> - 2011-05-09 14:22 -0700
Re: pthread question "Chris M. Thomasson" <cristom@charter.net> - 2011-05-09 15:33 -0700
Re: pthread question David Schwartz <davids@webmaster.com> - 2011-05-10 01:22 -0700
Re: pthread question Geoff Clare <geoff@clare.See-My-Signature.invalid> - 2011-05-10 13:47 +0100
Re: pthread question Alexander Terekhov <terekhov@web.de> - 2011-05-10 17:53 +0200
Re: pthread question Geoff Clare <geoff@clare.See-My-Signature.invalid> - 2011-05-11 13:46 +0100
Re: pthread question Alexander Terekhov <terekhov@web.de> - 2011-05-11 16:19 +0200
Re: pthread question Geoff Clare <geoff@clare.See-My-Signature.invalid> - 2011-05-12 13:26 +0100
Re: pthread question Alexander Terekhov <terekhov@web.de> - 2011-05-12 15:28 +0200
Re: pthread question Geoff Clare <geoff@clare.See-My-Signature.invalid> - 2011-05-13 14:00 +0100
Re: pthread question Alexander Terekhov <terekhov@web.de> - 2011-05-13 22:59 +0200
Re: pthread question Geoff Clare <geoff@clare.See-My-Signature.invalid> - 2011-05-16 13:28 +0100
csiph-web