- I have just read this about the C++11 Memory Model - 12 Updates
- Read again i correct - 1 Update
- Since Delphi and FreePascal can reorder loads and stores when optimizing. - 1 Update
- static variable issue - 9 Updates
- getting comp.lang.c++ in eternal-september.org news server - 2 Updates
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Mar 19 01:00PM On Sat, 18 Mar 2017 22:44:26 -0400 > So, there is still a problem with C++, because so it is still error > prone if you forget C++11 atomic types to ensure sequential > consistency and it is less efficient with atomic types. That's wrong, in C++ atomics are not less efficient. To achieve full sequential consistency any language would use the same processor instructions to achieve that (usually, an MFENCE barrier on x86/64). And if you forget to use the correct types in any language, or fail to synchronize correctly, your program will fail. > So i still prefer Delphi and FreePascal that don't reorder loads and > stores. You are very naive. Of course the Delphi compiler reorders loads and stores, or it couldn't optimize, and it may indeed eliminate some of them entirely; and even if the Delphi compiler does not, the hardware might. What you probably mean is that the Delphi compiler does not reorder loads and stores when optimizing so as to violate its execution ordering guarantees. Neither does C++ with respect to its memory model, including its default of sequential consistency. The C++ memory model forbids compilers optimizing in a way which violates it. There are all sorts of optimizations a compiler can carry out on single threaded code that it cannot carry out on multi-threaded code. I say "probably" above because I do not think you understand how to program properly in Delphi either. You need to synchronize Delphi code when using multiple threads, just as you need to synchronize C++ code when using multiple threads. |
Ramine <toto@toto.net>: Mar 19 09:37AM -0400 On 3/19/2017 9:00 AM, Chris Vine wrote: > program properly in Delphi either. You need to synchronize Delphi code > when using multiple threads, just as you need to synchronize C++ code > when using multiple threads. This is not my fault, delphi and freepascal has not inform us on that, so i have just read on internet and that was not sufficient, so i think that Delphi and FreePascal can reorder loads and stores, so what i must do now is use the syncobjs unit to be able to synchronize correctly and be sequential consistent: Here it is: http://www.freepascal.org/docs-html/3.0.0/fcl/syncobjs/tcriticalsection.html So i will update all my projects soon. Thank you, Amine Moulay Ramdane. |
Ramine <toto@toto.net>: Mar 19 09:39AM -0400 On 3/19/2017 9:00 AM, Chris Vine wrote: > program properly in Delphi either. You need to synchronize Delphi code > when using multiple threads, just as you need to synchronize C++ code > when using multiple threads. This is not my fault, delphi and freepascal have not inform us on that, so i have just read on internet and that was not sufficient, so i think that Delphi and FreePascal can reorder loads and stores, so what i must do now is use the syncobjs unit to be able to synchronize correctly and be sequential consistent: Here it is: http://www.freepascal.org/docs-html/3.0.0/fcl/syncobjs/tcriticalsection.html So i will update all my projects soon. Thank you, Amine Moulay Ramdane. |
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Mar 19 01:54PM On Sun, 19 Mar 2017 09:37:29 -0400 > On 3/19/2017 9:00 AM, Chris Vine wrote: [snip] > so i think that Delphi and FreePascal can reorder loads and stores, > so what i must do now is use the syncobjs unit to be able to > synchronize correctly and be sequential consistent: I think the problem is that you are very naive and confused. Synchronizing multiple threads correctly is not just about how the compiler optimizes: that is a necessary but very small part of it. You cannot guarantee the ordering of memory operations between threads just by turning compiler optimizations off. Synchronization goes to the hardware level. The only way two or more threads running on different cores on modern hardware can be guaranteed to see the same values in memory at any given time and the same modification order of different memory locations is by having the compiler issue the correct processor instructions to procure this. One way of having the compiler do this is to use mutexes, which automatically synchronize. Another way of doing it is to use atomic variables with the correct memory ordering. No language provides or can provide short cuts for this. |
Ramine <toto@toto.net>: Mar 19 10:09AM -0400 On 3/19/2017 9:54 AM, Chris Vine wrote: > automatically synchronize. Another way of doing it is to use atomic > variables with the correct memory ordering. > No language provides or can provide short cuts for this. What i am saying that TCriticalSection of Delphi and FreePascal ensures that all is correct, but if you want to code my MLock or my AMLock algorithms you have to use C++, because Delphi and FreePascal can reorder loads and stores and you can not do anything about it. But that's easy in FreePascal and Delphi , i will just use TCriticalSection of syncobjs unit, and i will use a Mutex on Windows and Linux provided by the FreePascal compiler on Windows and Linux.. So i will update soon my projects. Thank you, Amine Moulay Ramdane. |
Ramine <toto@toto.net>: Mar 19 10:14AM -0400 On 3/19/2017 9:54 AM, Chris Vine wrote: > automatically synchronize. Another way of doing it is to use atomic > variables with the correct memory ordering. > No language provides or can provide short cuts for this. And i think i will code my MLock and AMlock algorithms with C++ and C++ atomic types, because they can not be implemented with Delhi or FreePascal. Thank you, Amine Moulay Ramdane,. |
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Mar 19 02:17PM On Sun, 19 Mar 2017 10:09:46 -0400 Ramine <toto@toto.net> wrote: [snip] > my MLock or my AMLock algorithms you have to use C++, because Delphi > and FreePascal can reorder loads and stores and you can not do > anything about it. You still don't understand. It is not just about the reordering of loads and stores (which you could deal with by switching optimization off). It is a question of procuring synchronization in the hardware itself. If Delphi only provides mutexes/critical sections to do this, and you want to use atomic variables for efficiency reasons, then yes you need to use a better language. |
Ramine <toto@toto.net>: Mar 19 10:22AM -0400 On 3/19/2017 10:17 AM, Chris Vine wrote: > loads and stores (which you could deal with by switching optimization > off). It is a question of procuring synchronization in the hardware > itself. What i have said is that mutex and TCriticalsection of Delphi and FreePascal provide that. If Delphi only provides mutexes/critical sections to do this, > and you want to use atomic variables for efficiency reasons, then yes > you need to use a better language. And i think i will code my MLock and AMlock algorithms with C++ and C++ atomic types, because they can not be implemented with Delphi or FreePascal, i know that you can switch optimization off to avoid memory reordering , but i don't like this way. Thank you, Amine Moulay Ramdane,. |
Ramine <toto@toto.net>: Mar 19 10:28AM -0400 On 3/19/2017 10:22 AM, Ramine wrote: > memory reordering , but i don't like this way. > Thank you, > Amine Moulay Ramdane,. Here is what i will do: I will set optimization off in the source code of MLock and AMLock and the TicketSpinlock with a proportional back-off: by using this in FreePascal: {$OPTIMIZATION ON} http://www.freepascal.org/docs-html/prog/progsu58.html and by using this in Delphi: {$O-} http://docwiki.embarcadero.com/RADStudio/Seattle/en/Optimization_(Delphi) This way is easy, so i will updated my projects soon. That's all, Amine Moulay Ramdane. |
Ramine <toto@toto.net>: Mar 19 10:28AM -0400 On 3/19/2017 10:17 AM, Chris Vine wrote: > itself. If Delphi only provides mutexes/critical sections to do this, > and you want to use atomic variables for efficiency reasons, then yes > you need to use a better language. Here is what i will do: I will set optimization off in the source code of MLock and AMLock and the TicketSpinlock with a proportional back-off: by using this in FreePascal: {$OPTIMIZATION ON} http://www.freepascal.org/docs-html/prog/progsu58.html and by using this in Delphi: {$O-} http://docwiki.embarcadero.com/RADStudio/Seattle/en/Optimization_(Delphi) This way is easy, so i will updated my projects soon. That's all, Amine Moulay Ramdane. |
Ramine <toto@toto.net>: Mar 19 10:32AM -0400 On 3/19/2017 10:17 AM, Chris Vine wrote: > itself. If Delphi only provides mutexes/critical sections to do this, > and you want to use atomic variables for efficiency reasons, then yes > you need to use a better language. Sorry i correct: Here is what i will do: I will set optimization off in the source code of MLock and AMLock and the TicketSpinlock with a proportional back-off: by using this in FreePascal: {$OPTIMIZATION OFF} http://www.freepascal.org/docs-html/prog/progsu58.html and by using this in Delphi: {$O-} http://docwiki.embarcadero.com/RADStudio/Seattle/en/Optimization_(Delphi) This way is easy, so i will updated my projects soon. That's all, Amine Moulay Ramdane. |
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Mar 19 02:40PM On Sun, 19 Mar 2017 10:28:39 -0400 Ramine <toto@toto.net> wrote: [snip] > {$O-} > http://docwiki.embarcadero.com/RADStudio/Seattle/en/Optimization_(Delphi) > This way is easy, so i will updated my projects soon. I have now explained the problem to you three times and you are _still_ too obtuse to understand it. On multi-core machines switching off optimization WOULD NOT WORK, because there is NO SYNCHRONIZATION. The problem is not just one of reordering loads and stores. Please stop publicizing your code, and posting on this newsgroup, until you have acquired the minimum knowledge to qualify you to do so. You are a walking disaster area. |
Ramine <toto@toto.net>: Mar 19 10:32AM -0400 Hello... Since Delphi and FreePascal can reorder loads and stores when optimizing. Here is what i will do: I will set optimization off in the source code of MLock and AMLock and the TicketSpinlock with a proportional back-off: by using this in FreePascal: {$OPTIMIZATION OFF} http://www.freepascal.org/docs-html/prog/progsu58.html and by using this in Delphi: {$O-} http://docwiki.embarcadero.com/RADStudio/Seattle/en/Optimization_(Delphi) This way is easy, so i will updated my projects and C++ projects soon. That's all, Amine Moulay Ramdane. |
Ramine <toto@toto.net>: Mar 19 10:30AM -0400 Hello, Since Delphi and FreePascal can reorder loads and stores when optimizing. Here is what i will do: I will set optimization off in the source code of MLock and AMLock and the TicketSpinlock with a proportional back-off: by using this in FreePascal: {$OPTIMIZATION ON} http://www.freepascal.org/docs-html/prog/progsu58.html and by using this in Delphi: {$O-} http://docwiki.embarcadero.com/RADStudio/Seattle/en/Optimization_(Delphi) This way is easy, so i will updated my projects and C++ projects soon. That's all, Amine Moulay Ramdane. |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Mar 19 05:39AM +0100 >> #ExecuteBefore currAsync[8648] 0x212b5d0 //in execute_before >> #updateShadowMemW currAsync[8648] 0 //in updateShadowMemR > nothing else has been done with this variable between these calls. Well, there's one additional possible cause. If this is in Windows, and hence your "dynamic library" is a DLL, then dpst::currAsync in the DLL is not the same as dpst::currAsync in the main application, unless it's exported – and I see no signs of that. This is because Windows DLLs, unlike *nix shared libraries, are separate, language independent entities with internal code and state. The Window terminology is "module". Each DLL and executable is a "module", and is represented as a PE (Portable Executable) format file. Each module is defined by its imports and exports, which are designed to be language independent: no support for C++ classes, so C++ compilers have to fudge class exports and imports in various ways. I don't think that problem is common in *nix-land, but I'm not very familiar with *nix-land. Cheers!, - Alf |
Paavo Helde <myfirstname@osa.pri.ee>: Mar 19 10:13AM +0200 > std::cout<<"updateShadowMemR threadid "<<threadid<<" currAsync[threadid] "<<currAsync[threadid]; > } > } As Alf said, it is indeed possible you have a case of "split personality", i.e. there is not a single physical instance of the static currAsync array as you think, but more. This might be caused by Windows DLL peculiarities, but also for example if class dspt is actually a class template and you instantiate it with slightly different types in different places. To fight with the DLL split: 1. Move all the functions accessing currAsync offline into a .cpp file which is compiled only into a single DLL. 2. Fix all ensuing compiler and linker errors by adding needed dllexport specifiers/macros and linker options. 3. Done. In general, static variables should be best avoided as they do not scale and cause a myriad of other problems. The client software should first create an "engine" or "context" object via the special "init-library" routine. This object would contain the data that was static before. The client will pass the pointer to this object to all library functions needing it (either as 'this' or as a normal parameter). Voila, now the client has for example an ability to create two different thread pools if it ever feels like so. As a bonus, the thing will work regardless of the DLL boundary issues and static initialization order fiascos. |
sangitachowdhary@gmail.com: Mar 19 06:10AM -0700 On Sunday, March 19, 2017 at 4:14:02 AM UTC-4, Paavo Helde wrote: > thread pools if it ever feels like so. As a bonus, the thing will work > regardless of the DLL boundary issues and static initialization order > fiascos. I am on linux using g++. |
Paavo Helde <myfirstname@osa.pri.ee>: Mar 19 03:36PM +0200 >> class template and you instantiate it with slightly different types in >> different places. > I am on linux using g++. Then you have a more interesting bug. For debugging you can print out the address of the array itself, then it becomes clear whether this is physically the same array or not. If same, then put a data breakpoint there after assigning thenon-zero value; this will be triggered if/when the value unexpectedly goes back to zero. My general suggestion to avoid mutable static variables still holds. |
sangitachowdhary@gmail.com: Mar 19 06:50AM -0700 On Sunday, March 19, 2017 at 9:36:52 AM UTC-4, Paavo Helde wrote: > there after assigning thenon-zero value; this will be triggered if/when > the value unexpectedly goes back to zero. > My general suggestion to avoid mutable static variables still holds. You are right, there are two different instances of same static variable, I am getting different address, but I am wondering why this is the case. |
Paavo Helde <myfirstname@osa.pri.ee>: Mar 19 03:57PM +0200 >>>> On 19.03.2017 3:08, sangitachowdhary@gmail.com wrote: >>>>> I have one issue while using static variable. I have class dpst in my dynamic library, I am setting value for static variable in execute_before which is called inside library and in another function which is called from application I am reading its value. Unfortunately when I read value in updateShadowMemR from application it gives its value 0. I am not able to understand why? currAsync is class static variable which is read and set inside static function. Any help would be appreciated. > You are right, there are two different instances of same static variable, I am getting different address, but I am wondering why this is the case. And this is not a template class? |
sangitachowdhary@gmail.com: Mar 19 07:01AM -0700 On Sunday, March 19, 2017 at 9:57:48 AM UTC-4, Paavo Helde wrote: > >>>>> I have one issue while using static variable. I have class dpst in my dynamic library, I am setting value for static variable in execute_before which is called inside library and in another function which is called from application I am reading its value. Unfortunately when I read value in updateShadowMemR from application it gives its value 0. I am not able to understand why? currAsync is class static variable which is read and set inside static function. Any help would be appreciated. > > You are right, there are two different instances of same static variable, I am getting different address, but I am wondering why this is the case. > And this is not a template class? No, its not. |
Paavo Helde <myfirstname@osa.pri.ee>: Mar 19 04:09PM +0200 >>> You are right, there are two different instances of same static variable, I am getting different address, but I am wondering why this is the case. >> And this is not a template class? > No, its not. Ok, but is the class definition fully inline (present in the header file)? |
Paavo Helde <myfirstname@osa.pri.ee>: Mar 19 04:26PM +0200 On 19.03.2017 16:09, Paavo Helde wrote: >>> And this is not a template class? >> No, its not. > Ok, but is the class definition fully inline (present in the header file)? I mean, the definition of the static array must be placed outside of the class definition itself. In which file is this static array definition? Is this file compiled only into the shared library? |
Jorgen Grahn <grahn+nntp@snipabacken.se>: Mar 19 10:09AM On Sat, 2017-03-18, Jens Thoms Toerring wrote: > thing with a graphical user interface, but, prefering > text-only myself, I can' make any recommendations. > Others here will have better advice. I think that's what prompted the questions: David Brown recommended Thunderbird in and around <oaha6j$ift$1@dont-email.me>, and Kushal agreed to try to upgrade from Google Groups. I use slrn myself, so I can't really give advice here. /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o . |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Mar 19 11:36AM +0100 On 18-Mar-17 10:52 AM, kushal bhattacharya wrote: > Hi, > How do i get this group into the newsserver.PLease show me some sample example about this I found this: <url: https://groups.google.com/forum/#!topic/alt.usage.english/NgImZXOS8oM> ---------------------------------------------------------------------- If you are having no luck with usenet and newsgroups, you can get free access to this news server: news.eternal-september.org Free registration is available at: http://eternal-september.org/ I just successfully configured Thunderbird 3.1.11 for this server. Here's how: When you register you will be given a password which you will need at step 15 below 1. In Thunderbird, click File/New/Other Accounts 2. Click the button to select "newsgroup account" 3. Click "Next" 4. Enter your choice of displayed name 5. Enter an email address other users can see 6. Enter the name of the newsgroup server: news.eternal-september.org 7. Enter your choice of name to describe the eternal-september account 8. Click Finish, or Back to make corrections, then Finish 9. Click on the name of the account now listed in the left pane in Thunderbird 10. Click on View Settings. Your chosen name and email address are shown. 11. In the left window below the new account name, select Server Settings. Important: be sure you are selecting the Serve Settings for the account you just created and no other. 12. Check the box: "Always request authentication" 13. Important: do not change any outgoing server settings. Use the same outgoing server settings as you use for email 14. Back in Thunderbird, make sure your new account is selected and click on "Manage Newsgroup Subscriptions". In the window, click on Current Group tab. If no groups appear, click "refresh". 15. Be very careful at this point to respond with the correct information. Don't enter the password when it's asking for your username. The server will ask for your username first. You must enter only the username you registered with at eternal-september. Then it will ask for your password, which you received in an email from eternal-september (or your current one if you changed it). 16. If you make or have made a mistake at Step 15 (wrong username or password), close Thunderbird, reopen it and repeat from step 14. 17. If you receive the message "invalid credentials", check that you have carefully and accurately followed Steps 1-13. If not, repeat from Step 6. 18. Back in the Subscribe window, you should still be in the Current Groups tab. If no newsgroups are listed, click "Refresh.". 19. Select the news groups to subscribe to, making you sure do two things. Check the box next to the group you want and click on "Subscribe" in the window. 20. Follow the prompts to choose how many messages to download for each group The default of 500 will get you started. If you want more later, click on the newsgroup in the pane at the left in Thunderbird (not the account name) and then click File/Get Next/500 messages 21. Use the View menu to customise how your messages are displayed |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment