Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming.threads > #554
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!goblin2!goblin.stu.neva.ru!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail |
|---|---|
| From | Edek <edek.pienkowski@gmail.com> |
| Newsgroups | comp.programming.threads |
| Subject | Re: Thread safe logging (or protecting global variables) |
| Date | Fri, 09 Sep 2011 18:13:58 +0200 |
| Organization | ATMAN - ATM S.A. |
| Lines | 43 |
| Message-ID | <j4de6e$u92$1@node2.news.atman.pl> (permalink) |
| References | <Co89q.7290$cb.3785@newsfe14.ams2> <j434mo$6cj$1@node2.news.atman.pl> <49s9q.1564$8D1.58@newsfe19.ams2> <j47ah3$t3k$1@node2.news.atman.pl> <h99aq.1220$MZ.469@newsfe06.ams2> |
| NNTP-Posting-Host | 178-37-131-101.adsl.inetia.pl |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | node2.news.atman.pl 1315585038 31010 178.37.131.101 (9 Sep 2011 16:17:18 GMT) |
| X-Complaints-To | usenet@atman.pl |
| NNTP-Posting-Date | Fri, 9 Sep 2011 16:17:18 +0000 (UTC) |
| User-Agent | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110428 Linux/3.1.0-15 Thunderbird/3.1.0 |
| In-Reply-To | <h99aq.1220$MZ.469@newsfe06.ams2> |
| Xref | x330-a1.tempe.blueboxinc.net comp.programming.threads:554 |
Show key headers only | View raw
On 09/08/2011 10:00 PM, Jef Driesen wrote: >>>>> Can I even go one step futher and use simple a simple flag (like the >>>>> g_loglevel variable above) that can only be modified from the >>>>> message_set_*() functions, and which is only checked in the message() >>>>> function but not modified. >>>> >>>> Will work on x86, but there is no guarantee it won't break on any other >>>> CPU or on some new hardware a couple years later. >>>> >>>> An atomic would be enough - either the new standard, or find an >>>> assembly that makes one for the target CPU, a couple of libraries have >>>> been doing that for a long time. For example, logging libraries. >>> >>> I understand (in theory at least) how atomic operations can be used to >>> protect a single variable like the g_loglevel flag in my example code. >>> But how does this work (if that's even possible) if the logging state >>> consists of multiple variables? >> >> I do not see why a logging library would need to access atomically >> a structure containing both log levels and the sink. >> >> If you do not care about optimisations (for the 'logging off' case), >> then you can create a larger structure and make it atomic. >> >> Atomics are supported by CPUs up to some size; if larger they need to be >> emulated, usually by locking a mutex (or a spinlock) and using >> the data in the structure > > Can you explain in a little more detail what you mean here? I'm a little > lost. Which part? The first one and the second one is 'why do you want to do that?'. How are you going to write your logging framework? With a single level? With a hierarchy of loggers? Just global structures, or each logger having a flag? The third one explains how atomicity is done for many variables - as long as they can be packed in one structure. Edek
Back to comp.programming.threads | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Thread safe logging (or protecting global variables) Jef Driesen <jefdriesen@hotmail.com.invalid> - 2011-09-05 20:19 +0200
Re: Thread safe logging (or protecting global variables) Edek <edek.pienkowski@gmail.com> - 2011-09-05 20:30 +0200
Re: Thread safe logging (or protecting global variables) Jef Driesen <jefdriesen@hotmail.com.invalid> - 2011-09-06 18:48 +0200
Re: Thread safe logging (or protecting global variables) Edek <edek.pienkowski@gmail.com> - 2011-09-07 10:34 +0200
Re: Thread safe logging (or protecting global variables) Jef Driesen <jefdriesen@hotmail.com.invalid> - 2011-09-08 22:00 +0200
Re: Thread safe logging (or protecting global variables) Edek <edek.pienkowski@gmail.com> - 2011-09-09 18:13 +0200
Re: Thread safe logging (or protecting global variables) Jef Driesen <jefdriesen@hotmail.com.invalid> - 2011-09-13 17:58 +0200
Re: Thread safe logging (or protecting global variables) Joshua Maurice <joshuamaurice@gmail.com> - 2011-09-13 13:18 -0700
Re: Thread safe logging (or protecting global variables) Jef Driesen <jefdriesen@hotmail.com.invalid> - 2011-09-14 07:16 +0200
Re: Thread safe logging (or protecting global variables) Joshua Maurice <joshuamaurice@gmail.com> - 2011-09-14 13:18 -0700
Re: Thread safe logging (or protecting global variables) Edek <edek.pienkowski@gmail.com> - 2011-09-14 09:33 +0200
Re: Thread safe logging (or protecting global variables) Alexander Terekhov <terekhov@web.de> - 2011-09-14 13:17 +0200
Re: Thread safe logging (or protecting global variables) Joshua Maurice <joshuamaurice@gmail.com> - 2011-09-14 13:03 -0700
Re: Thread safe logging (or protecting global variables) Joshua Maurice <joshuamaurice@gmail.com> - 2011-09-14 13:19 -0700
Re: Thread safe logging (or protecting global variables) "James" <no@spam.invalid> - 2011-09-14 19:19 -0700
Re: Thread safe logging (or protecting global variables) Joshua Maurice <joshuamaurice@gmail.com> - 2011-09-14 21:03 -0700
Re: Thread safe logging (or protecting global variables) Alexander Terekhov <terekhov@web.de> - 2011-09-15 13:12 +0200
Re: Thread safe logging (or protecting global variables) Joshua Maurice <joshuamaurice@gmail.com> - 2011-09-15 12:24 -0700
Re: Thread safe logging (or protecting global variables) Alexander Terekhov <terekhov@web.de> - 2011-09-15 22:22 +0200
Re: Thread safe logging (or protecting global variables) "James" <no@spam.invalid> - 2011-09-15 13:33 -0700
Re: Thread safe logging (or protecting global variables) Joshua Maurice <joshuamaurice@gmail.com> - 2011-09-15 15:36 -0700
Re: Thread safe logging (or protecting global variables) Joshua Maurice <joshuamaurice@gmail.com> - 2011-09-15 15:36 -0700
Re: Thread safe logging (or protecting global variables) Alexander Terekhov <terekhov@web.de> - 2011-09-16 16:28 +0200
Re: Thread safe logging (or protecting global variables) Joshua Maurice <joshuamaurice@gmail.com> - 2011-09-16 15:06 -0700
Re: Thread safe logging (or protecting global variables) Alexander Terekhov <terekhov@web.de> - 2011-09-17 12:50 +0200
Re: Thread safe logging (or protecting global variables) Alexander Terekhov <terekhov@web.de> - 2011-09-15 12:50 +0200
Re: Thread safe logging (or protecting global variables) Edek <edek.pienkowski@gmail.com> - 2011-09-14 09:17 +0200
Re: Thread safe logging (or protecting global variables) Joshua Maurice <joshuamaurice@gmail.com> - 2011-09-08 16:28 -0700
Re: Thread safe logging (or protecting global variables) Joshua Maurice <joshuamaurice@gmail.com> - 2011-09-08 16:33 -0700
Re: Thread safe logging (or protecting global variables) Joshua Maurice <joshuamaurice@gmail.com> - 2011-09-08 20:55 -0700
Re: Thread safe logging (or protecting global variables) Joshua Maurice <joshuamaurice@gmail.com> - 2011-09-12 00:45 -0700
csiph-web