Xref: csiph.com comp.arch:33503 Newsgroups: comp.arch Path: csiph.com!xmission!news.glorb.com!border1.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!kithrup.com!mrs From: mrs@kithrup.com (Mike Stump) Subject: Re: The freedom that give us C++ and C Message-ID: Date: Sat, 6 Feb 2016 08:59:42 GMT References: Organization: Kithrup Enterprises, Ld. X-Newsreader: trn 4.0-test77 (Sep 1, 2010) Lines: 82 In article , Nick Maclaren wrote: >In article , Mike Stump wrote: >In the case of C++, when you are using C++11 threading, then perhaps. >But it does not help for OpenMP or asynchronous I/O. OpenMP isn't part of the C++ nor C standards, so, it is defined not by the standard, but by OpenMP. Since async I/O can be done in C11 and C++11 using atomics and threads in those languages both portable and in a defined manner, _and_ do it locklessly, I really don't see a problem. >In the case of C, no, it doesn't help. Unlike C++, C11 did not >remove all of them the old sequence point rules, or the rest of the >ordering text, and God alone knows what happens when they conflict. So what? You can't update a variable twice between sequence points, so what. This doens't prohibit one from writing correct, defined, performant and standard code. That is as stupid as saying that because one can't divide by 0, C has no useful division operation. My claim, is that you can divide quite a few other numbers and people that want to use divide are happy enough with the values that can be operated on. The entire point of things like stdatomic.h and threads.h is to introduce enough functionality to be able to write useful things. Sure, the atomic lockless operation that would do a saturating multiple with a bias adjustment isn't in the language standard, true, but, plus is. For machines that can do plus, atomically, you can now get at the operation from standard code. If you have a point, maybe you can expound on what you can't do, that you think makes the standard worthless. Also, because it defines sync between threads, things like mmap, though, even if not defined in the standard, one can use things like stdatomic.h, now, portably to write lock free code from different processes and mmapped files just fine. It is a misunderstanding on your part, if you think otherwise. Now, one can mmap a file from a remote filsystem and there are some that don't offer enough beef to make everything work flawlessly between boxes, but that has more to do with the remote filesystem and locking and their mmap primative. Mapping files from remote filesystems is beyond the C/C++ standards, so, this doesn't violate the standard, but at the same time, that lack, doesn't mean that stdatomic.h isn't useful when working on a non-remote filesystem on a single machine. >Also, in neither case are the non-atomic compound operators properly >specified, and the model is entirely in terms of loads, stores, and >atomic read-modify-write (which isn't enough for x = ++a, even if the >++a is atomic). I tried to get that nailed down in C++, but it wasn't >done because it was beyond the state of the art (in computer science >parallel theory). Right. x = ++a may not be there, and you may want it. I get that. The problem is that the standard offers what a lot of machines have and can offer. Even my machine doesn't have x = ++a, and I have a ton of really, really nice sync stuff. More than most. The problem is if memories don't have it, and people don't need it, there isn't any point in having the language support it. If a machine had it, one can trivially add it, and even though it is beyond the standard today, the next version can add it if useful. In my machine, for example, I _can't_ lock both. I can lock either the ++a part or the x = part, just not both. There are reasons why it simply is impossible to ever do that. Now, from a language theoretic view, I wish they had done something like x = atomic (++a), or atomic (x = ++a), then you could have anything in there and the compiler would figure out if your CPU had the operation or not. As new cpus added more atomic primatives, things like: atomic { int t = a; a = b; b = t; } fall out, the semantics are clear, and a future compiler for a future architecture can seemlessly then offer that as a fully lockless snippet, even if it wasn't available originally. Oh well. I wans't in the room when C++ added it, so I take no responsibility for the incantation that they choose. I do agree, I think it is wrong (non-optimal).