using __tm_atomic in template class member function

using __tm_atomic in template class member function

There seems to be some problems when using __tm_atomic in template class member functions. I got errors whenever I put __tm_atomic regions in those functions. Here's the test case:

#include 
using namespace std;
template 
class Ptr{
private:
T *p;
public:
Ptr(T *x):p(x){}
int Equal(T *q){
__tm_atomic{}
return p==q?1:0;
}
};
int main()
{
int a=3;
int *p_a=&a;
Ptr ptr_a(&a);
cout<}

And the error message is:

$ icpc -Qtm_enabled try_atomic.cpp
try_atomic.cpp(23): error: expected a "}"
try_atomic.cpp(23): internal error: assertion failed at: "shared/edgcpfe/templates.c", line 2897

The code would compile if the class were not a template class. Is it a bug or that I shouldn't use it this way? Thanks.

btw, I'm using the Linux version of prototype edition 2.0

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Jiaq,

First: Your Equal function should not require an atomic section.

Second: your __tm_atomic{} block is null

Third: if you wish to use atomic regardless then try:

 int Equal(T *q){
return __tm_atomic{p==q?1:0;};
};
Jim Dempsey
www.quickthreadprogramming.com

Hi, Jim,

Thanks very much for your instructions. However, the code is just a test case without any meaning, and I just made it as simple as possible. So pls ignore the semantics. I just want to show that there is an error whenever I put a whateveratomicsection in the function.

I also tried your code and itneither works.

It also fails on Windows with the same error message by the way.

This is a bug in current posted compiler. Will be addressed in the next compiler release.

Leave a Comment

Please sign in to add a comment. Not a member? Join today