public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "davids at webmaster dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/20099] -pthreads should imply -fno-threadsafe-statics Date: Sun, 20 Feb 2005 17:15:00 -0000 [thread overview] Message-ID: <20050220104807.6020.qmail@sourceware.org> (raw) In-Reply-To: <20050220004607.20099.davids@webmaster.com> ------- Additional Comments From davids at webmaster dot com 2005-02-20 10:48 ------- There is certainly the eternal argument whether a class should implement its own locks internally or whether the caller should implement them. The first case simplifies calling at the expense of overhead when you don't need it. The second makes callers have more knowledge of how the functions they're calling work, but make possible optimizations in cases where the locks aren't needed, and only the caller knows this. POSIX made this decision. The POSIX memory visibility rules specifically require a mutex to be held in cases where an object may be modified by another concurrent thread. So POSIX code *must* already contain such mutexes. This requirement in POSIX is as clear as anything can be. The rationale is that on some platforms, locks may be very expensive, so requiring them implicitly was carefully avoided. POSIX requires shared data to be explicitly locked by application code when data might be modified in one thread and read in another concurrently. While the C++ standard doesn't say anything about threads, it says a lot about how static objects are initialized. It specifies initialization on first use, thus first use is a modification. Use that might be first use might be a modification. There is no other sensible reading of the POSIX standard. There is no other sensible reading of the C++ standard. The arguments presented are disingenous. They would equally well defend the decision to initialize all static objects before calling 'main' in multithreaded code. After all, C++ doesn't say anything about multithreaded code and POSIX doesn't say anything about initializating C++ static objects. In fact, the arguments would defend crashing on any multithreaded C++ code, which is obviously not what anyone wants. If there is going to be C++/POSIX code, the C++ standard and the POSIX standard will have to be made to coexist. POSIX requires the application to figure out when objects may be accessed concurrently, and does so for good reason. In a non-POSIX context, it may make sense to have the compiler try to automatically insert mutexes, but it definitely doesn't in the POSIX case. The compiler should, by default, make the optimizations that the standards permit. This is the way every other similar option has been implemented. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20099
next prev parent reply other threads:[~2005-02-20 10:48 UTC|newest] Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top 2005-02-20 13:52 [Bug c++/20099] New: " davids at webmaster dot com 2005-02-20 14:17 ` [Bug c++/20099] " pinskia at gcc dot gnu dot org 2005-02-20 14:18 ` davids at webmaster dot com 2005-02-20 14:18 ` pinskia at gcc dot gnu dot org 2005-02-20 14:22 ` pinskia at gcc dot gnu dot org 2005-02-20 15:07 ` davids at webmaster dot com 2005-02-20 15:11 ` davids at webmaster dot com 2005-02-20 15:37 ` pinskia at gcc dot gnu dot org 2005-02-20 17:07 ` qrczak at knm dot org dot pl 2005-02-20 17:15 ` davids at webmaster dot com [this message] 2005-02-20 18:12 ` qrczak at knm dot org dot pl 2005-02-21 9:29 ` davids at webmaster dot com 2005-02-21 12:04 ` qrczak at knm dot org dot pl 2005-02-21 15:45 ` gniccolai at yahoo dot com 2005-02-21 16:34 ` davids at webmaster dot com 2005-02-22 15:59 ` gniccolai at yahoo dot com 2005-02-23 11:55 ` davids at webmaster dot com 2005-02-23 11:57 ` qrczak at knm dot org dot pl 2005-02-23 12:26 ` pinskia at gcc dot gnu dot org 2005-02-23 12:28 ` davids at webmaster dot com 2005-02-24 15:28 ` gniccolai at yahoo dot com 2005-02-24 20:00 ` gniccolai at yahoo dot com 2005-02-24 22:02 ` qrczak at knm dot org dot pl 2005-02-25 1:37 ` davids at webmaster dot com 2005-02-25 1:41 ` qrczak at knm dot org dot pl 2005-02-25 3:30 ` davids at webmaster dot com 2005-02-25 4:37 ` qrczak at knm dot org dot pl 2005-02-25 8:06 ` davids at webmaster dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20050220104807.6020.qmail@sourceware.org \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).