- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I just had a nice transactional memory idea that might make transactional memory portable across CPUs having similar facilities like TSX on Intel-CPUs.
The idea is to encapsulate the transaction in a C++ lamda. Look at this code:
template<typename L> inline int transaction( L &lambda ) { unsinged code = _xbegin(); if( code == _XBEGIN_STARTED ) { lambda(); _xend(); return 1; } else return (code & (_XABORT_RETRY | _XABORT_EXPLICIT)) == _XABORT_RETRY ? 0 : -1; } ... auto trans = []() { ... do transacton }; transaction<decltype(trans)>( trans );
transaction<>() returns everything which is necessary: > 0 if the transaction is successful, 0 if it is aborted but could be retried and < 0 if it is aborted and can't retried.
Unfortunately C++ is too stupid as to decuce the template-parameter I specify with decltype(trans) from the parameter to transaction(). otherwise I could place the lamda directly into the function-call. Hopefully another upcoming C++ standard will have a template-parameter-decuction for this.
- Tags:
- Intel® Advanced Vector Extensions (Intel® AVX)
- Intel® Streaming SIMD Extensions
- Parallel Computing
Link Copied
0 Replies
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page