Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming.threads > #560
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!plix.pl!newsfeed1.plix.pl!wsisiz.edu.pl!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 | Wed, 14 Sep 2011 09:17:08 +0200 |
| Organization | ATMAN - ATM S.A. |
| Lines | 37 |
| Message-ID | <j4pkjd$cav$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> <j4de6e$u92$1@node2.news.atman.pl> <M4Lbq.15823$xz.12103@newsfe09.ams2> |
| NNTP-Posting-Host | 81.219.114.60 |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | node2.news.atman.pl 1315984813 12639 81.219.114.60 (14 Sep 2011 07:20:13 GMT) |
| X-Complaints-To | usenet@atman.pl |
| NNTP-Posting-Date | Wed, 14 Sep 2011 07:20:13 +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 | <M4Lbq.15823$xz.12103@newsfe09.ams2> |
| Xref | x330-a1.tempe.blueboxinc.net comp.programming.threads:560 |
Show key headers only | View raw
>
>> The third one explains how atomicity is done for many variables -
>> as long as they can be packed in one structure.
>
> I have absolutely no idea how this works.
template <class T>
atomic {
private:
mutex m_mutex;
T m_val;
public:
void set(T t) {
scope_lock(m_mutex);
m_val = T;
}
T get() {
scope_lock(m_mutex);
return m_val;
}
}
The above is effectively an implementation of "atomic"
get and set (other operations elided) of T, if T
is a structure. It is simplified and unoptimised, but
it works. It works also e.g. for int, but for int
there is no need to employ a heavy mutex on most platforms.
Better implementations might use better tricks, but this
is sufficient - m_val of type T is accessed atomically.
T should be trivial enough, POD would be ok.
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