Re: [Boost-users] shared_ptr and weak_ptr concurrency
Just to make sure I understand, am I right that this assumes x86/x64
CPUs and only those built in types up to register size (no 64 bit
integers) and may not include single bytes in all circumstances?
If you wrote code that depended on this assumption how could you be sure
it wouldn't be ported to a box with a different CPU (I move stuff all
the time between x86 and AIX, HPUX and sometimes a VAX).
Can I make the same assumptions or not? And how can I be sure?
Thanks,
Jerry
Message: 1
Date: Fri, 4 Sep 2009 11:58:46 -0400
From: John Dlugosz
Just to make sure I understand, am I right that this assumes x86/x64 CPUs and only those built in types up to register size (no 64 bit integers) and may not include single bytes in all circumstances?
Right, no 64-bit integers under x86; only native register sizes. Single bytes might include bool types, but (in theory) a volatile value won't have such shenanigans on it.
If you wrote code that depended on this assumption how could you be sure it wouldn't be ported to a box with a different CPU (I move stuff all the time between x86 and AIX, HPUX and sometimes a VAX).
I encapsulate my thread stuff as tightly as possible. So in free code I should be making assumptions about atomicness of assignment; only that the assignment operator on my type is correctly written if documented to be atomic. So, don't allow that assumption to spill out into the program at large. Your queue or message or update or whatever will be encapsulated into a class that may use such tricks, and it can be altered if necessary for each platform. Document the class, including the thread guarantees. Put strict #ifdef's in the class, to ensure it is only used on the platform you tested it on. If the same code works on more than one, add to the #if when you vet it. For the other platforms, check the documentation, or experts using them. The details of the whole toolset of lock-free (and special atomic instruction free) programming will differ, but some things may be universal across them, like certain types (native register size) that are read and written atomically.
Can I make the same assumptions or not? And how can I be sure?
Thanks,
Jerry
Check the manual for that CPU, examine existing code that works on it, and write your own test code. For example, I make use of a "trick" that is not strictly allowed in the CPU manual, but works fine. My test program validates that, and it is run on each successive CPU generation to make sure it still works. --John TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.
participants (2)
-
Jerry Jeremiah
-
John Dlugosz