SERVING THE QUANTITATIVE FINANCE COMMUNITY

 
User avatar
Cuchulainn
Topic Author
Posts: 62591
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

C++ 11 Concurrency

September 5th, 2015, 7:34 am

QInstead of template<class T>shared_ptr<T> atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);is it 'better' to use std::atomic<std::shared_ptr> or is it even supported?
Last edited by Cuchulainn on September 4th, 2015, 10:00 pm, edited 1 time in total.
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
Polter
Posts: 2526
Joined: April 29th, 2008, 4:55 pm

C++ 11 Concurrency

September 5th, 2015, 11:09 am

Take a look at atomic_shared_ptr (Concurrency TS): http://www.justsoftwaresolutions.co.uk/ ... d_ptr.html
 
User avatar
Cuchulainn
Topic Author
Posts: 62591
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

C++ 11 Concurrency

September 6th, 2015, 2:27 pm

QuoteOriginally posted by: PolterTake a look at atomic_shared_ptr (Concurrency TS): http://www.justsoftwaresolutions.co.uk/ ... r.htmlIt's a good idea;)Shared_ptr (IMO) is the C++ equivalent of COBOL global data, FORTRAN common blocks or the dreaded design pattern SINGLETON. They were a blessing in disguise and went unnoticed in sequential code. The fun starts with multiple threads.Libraries that use shared ptr over the place are probably not parallelisable.Here is an example of non-thead-safe shared ptr, leading to "smart races".
Attachments
TestSharedPointerRaceCondition.zip
(1.37 KiB) Downloaded 24 times
Last edited by Cuchulainn on September 5th, 2015, 10:00 pm, edited 1 time in total.
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
Cuchulainn
Topic Author
Posts: 62591
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

C++ 11 Concurrency

September 13th, 2015, 8:09 am

QuoteOriginally posted by: dd3QuoteOriginally posted by: outrunBoost ASIO which might end up in C++17 has heavy lock congestionsOnly if you use OpenSSL with itAre there other possibilities?
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
Cuchulainn
Topic Author
Posts: 62591
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

C++ 11 Concurrency

September 13th, 2015, 8:11 am

QuoteOriginally posted by: PolterRegarding parallelism: It seems that parallel algorithms are coming first:http://www.open-std.org/JTC1/SC22/WG21/ ... fRegarding concurrency: Composable futures, task group, etc., are coming, too:http://www.open-std.org/JTC1/SC22/WG21/ ... 01.htmlThe good news is that both Parallelism TS and Concurrency TS are on the fast track to approval:http://isocpp.org/blog/2015/06/trip-rep ... meetingOne note on the concurrent containers -- these are non-trivial if you want a solution that will scale well into the future -- which includes working well with future hardware as well as future problems, with a design that will stand the test of time (we wouldn't necessarily want to end up with another vector<bool> or valarray...).One issue to take into account is transactional memory (instead of, say, locks -- which would defeat the purpose); Transactional Memory TS is very much worth a look in this context (as well as the Intel's TSX on the hardware side).Theoretically (and, as far as concurrency is concerned, getting the fundamentals right is not necessarily a bad idea before jumping right to the practical implementation) there are some unsolved problems here.For an illustration of what I mean and why is this important, I'd recommend "Unlocking Concurrency": http://queue.acm.org/detail.cfm?id=1189288First, it's indeed highly recommended to use an existing, mature, battle-tested library solution (quality matters -- the flip-side being: there are only so many high-quality choices available, including folks / organizations willing to spend their time / resources to write and defend proposals in this area...):QuoteIt is possible to write a concurrent hash-map data structure using locks so that you get both concurrent read accesses and concurrent accesses to disjoint data. In fact, the recent Java 5 libraries provide a version of HashMap, called ConcurrentHashMap, that does exactly this. The code for ConcurrentHashMap, however, is significantly longer and more complicated than the version using coarse-grained locking. The algorithm was designed by threading experts and it went through a comprehensive public review process before it was added to the Java standard. In general, writing highly concurrent lock-based code such as ConcurrentHashMap is very complicated and bug prone and thereby introduces additional complexity to the software development process.However, at the same time -- and despite the occasional optimistic expectations -- in fact, having a concurrent hash map in the standard library doesn't (and wouldn't) make "concurrency with hash maps" a solved problem (if the programmers actually want composability -- which is pretty fundamental for programs that are to stand the test of time):QuoteAlthough highly concurrent libraries built using fine-grained locking can scale well, a developer doesn?t necessarily retain scalability after composing larger applications out of these libraries. As an example, assume the programmer wants to perform a composite operation that moves a value from one concurrent hash map to another, while maintaining the invariant that threads always see a key in either one hash map or the other, but never in neither. Implementing this requires that the programmer resort to coarse-grained locking, thus losing the scalability benefits of a concurrent hash map (figure 3A). To implement a scalable solution to this problem, the programmer must somehow reuse the fine-grained locking code hidden inside the implementation of the concurrent hash map.It remains to be seen if, say, HTM / STM is the way to go (and which design point -- or points -- along the continuum of choices is -- or are -- "right").But the point about locks stands -- if the wish is to have STL containers with locks, a strictly superior approach (complexity _and_ performance) is to recompile the workload as a single-threaded application, since using a locks-based "concurrent" data structure would completely and purposefully defeat any benefits anyway:http://a248.e.akamai.net/f/1097/1823/7m ... /fig2.jpgI suppose as proposed hereBTW Don't suppose Boost has a "Parallel" yet?
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
Cuchulainn
Topic Author
Posts: 62591
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

C++ 11 Concurrency

September 15th, 2015, 1:35 pm

QuoteOriginally posted by: CuchulainnQuoteOriginally posted by: dd3QuoteOriginally posted by: outrunBoost ASIO which might end up in C++17 has heavy lock congestionsOnly if you use OpenSSL with itAre there other possibilities?SSL v2 is banned while v3 is deprecated, correct?Dead parrots v2 and V3?
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
Cuchulainn
Topic Author
Posts: 62591
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

C++ 11 Concurrency

September 15th, 2015, 3:41 pm

QuoteOriginally posted by: outrunQuoteOriginally posted by: CuchulainnQuoteOriginally posted by: CuchulainnQuoteOriginally posted by: dd3QuoteOriginally posted by: outrunBoost ASIO which might end up in C++17 has heavy lock congestionsOnly if you use OpenSSL with itAre there other possibilities?SSL v2 is banned while v3 is deprecated, correct?Dead parrots v2 and V3?OpenSSL is software, it apparently uses boost asio.? SSL is a protocol that allows you to communicate securely across channels that are wiretapped. But how can that be? If I send you a password and tell you to encrypt messages with it before you send them to me, then the NSA will have access to that password as well. How do you get started??Yes, there's a few libraries.Diffie-Hellman?QuoteWikipedia: "The Diffie?Hellman key exchange method allows two parties that have no prior knowledge of each other to jointly establish a shared secret key over an insecure communications channel. This key can then be used to encrypt subsequent communications using a symmetric key cipher."Is it better to use RFC 2818 for TLS? Better to disable SSL completely? I just don't know..
Last edited by Cuchulainn on September 14th, 2015, 10:00 pm, edited 1 time in total.
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
Cuchulainn
Topic Author
Posts: 62591
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

C++ 11 Concurrency

September 16th, 2015, 10:14 am

QuoteOriginally posted by: outrunCan you be more specific about the problem you try to solve? We are discussing software, protocols, crypto algorithms,..What are you looking at?* ssh access to your remote private server?* https for your website, are you pondering about the certificate you need to buy, ...or about how to delicately configure your webservers (which one, Apache, iis, nginx)* mailserver communicationssl is sometimes required, when someone needs to login a website it should always https, the worst configuration/variant is still better than nothing.I can say a bit: Send sensitive data (text, foto) over https (using asio/ssl on both Linux and Windows). There might be an Eve but with asymmetric keys is no problem? I have no idea.
Last edited by Cuchulainn on September 15th, 2015, 10:00 pm, edited 1 time in total.
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
dd3
Posts: 246
Joined: June 8th, 2010, 9:02 am

C++ 11 Concurrency

September 17th, 2015, 2:30 pm

QuoteOriginally posted by: CuchulainnQuoteOriginally posted by: outrunCan you be more specific about the problem you try to solve? We are discussing software, protocols, crypto algorithms,..What are you looking at?* ssh access to your remote private server?* https for your website, are you pondering about the certificate you need to buy, ...or about how to delicately configure your webservers (which one, Apache, iis, nginx)* mailserver communicationssl is sometimes required, when someone needs to login a website it should always https, the worst configuration/variant is still better than nothing.I can say a bit: Send sensitive data (text, foto) over https (using asio/ssl on both Linux and Windows). There might be an Eve but with asymmetric keys is no problem? I have no idea.If all you're doing is transferring files then ASIO is probably overkill. libcurl supports secure connections
 
User avatar
Cuchulainn
Topic Author
Posts: 62591
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

C++ 11 Concurrency

September 20th, 2015, 12:42 pm

Even though C+11 does not yet support concurrent containers, Boost does have
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
ABOUT WILMOTT

PW by JB

Wilmott.com has been "Serving the Quantitative Finance Community" since 2001. Continued...


Twitter LinkedIn Instagram

JOBS BOARD

JOBS BOARD

Looking for a quant job, risk, algo trading,...? Browse jobs here...


GZIP: On