Forum Jump

Select Group :
Select Forum :
Sorted By :
Sort Order :
From The :
 
Thread Tools  Search this thread 
feradz
Total Points:
15
Registered User
October 10, 2008 8:20 AM PDT
Testing abort with tm_pure

Hi I ma using the Intel STM C compiler version 2.0,

Ihave the following code bellow. when compiled

$icc -Qtm_enable test test.c

the value of "b" is 1 but is expected 0. It works for -O0 specified explicitly. Found it useful to share since users may waste quite a time understanding why getting wired variables when not compiling with -O0.

1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <pthread.h>
4
5 int abort_counter = 0;
6
7 __attribute__((tm_pure))
8 void increment_abort_counter()
9 {
10     abort_counter++;
11 }
12
13
14 int main()
15 {
16     int a = 0;
17     int b = 0;
18
19     __tm_atomic
20     {
21         a++;
22
23         increment_abort_counter();
24
25         __tm_atomic
26         {
27             b++;
28             increment_abort_counter();
29
30             if (abort_counter == 2)
31             {
32                 __tm_abort;
33             }
34         }
35     }
36
37     printf("abort_counter, expected 2, actual: %d\n", abort_counter);
38     printf("a, expected 1, actual: %d\n", a);
39     printf("b, expected 0, actual: %d\n", b);
40     return 0;
41 }

 

Ravi Narayanaswamy (Intel)
Total Points:
852
Status Points:
352
Brown Belt
October 10, 2008 4:47 PM PDT
Rate
 
|Best Answer
#1
Quoting - feradz

Hi I ma using the Intel STM C compiler version 2.0,

Ihave the following code bellow. when compiled

$icc -Qtm_enable test test.c

the value of "b" is 1 but is expected 0. It works for -O0 specified explicitly. Found it useful to share since users may waste quite a time understanding why getting wired variables when not compiling with -O0.

1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <pthread.h>
4
5 int abort_counter = 0;
6
7 __attribute__((tm_pure))
8 void increment_abort_counter()
9 {
10     abort_counter++;
11 }
12
13
14 int main()
15 {
16     int a = 0;
17     int b = 0;
18
19     __tm_atomic
20     {
21         a++;
22
23         increment_abort_counter();
24
25         __tm_atomic
26         {
27             b++;
28             increment_abort_counter();
29
30             if (abort_counter == 2)
31             {
32                 __tm_abort;
33             }
34         }
35     }
36
37     printf("abort_counter, expected 2, actual: %d\n", abort_counter);
38     printf("a, expected 1, actual: %d\n", a);
39     printf("b, expected 0, actual: %d\n", b);
40     return 0;
41 }

 


Yes the value of b should be 0.  This is a bug in the compiler,  when optimization is enabled we incorrectly propagate the value b++ to the print statement.   Next update should address this problem.





Intel Software Network Forums Statistics

8487 users have contributed to 31625 threads and 100705 posts to date.
In the past 24 hours, we have 36 new thread(s) 120 new posts(s), and 186 new user(s).

In the past 3 days, the most popular thread for everyone has been gemm(A,A,A) like possible? The most posts were made to gemm(A,A,A) like possible? The post with the most views is Dear Steve, excuse me for a d

Please welcome our newest member chat1983