The following simple test code shows race conditions with cilkscreen, even when all the variables
are local to the loop.
#include
using namespace std;
int cilk_main()
{
cilk_for(int i=0;i<3;i++)
{
string line="hi ashay here";
string res;
char *pch,*str;
str=(char*)line.c_str();
pch = strtok (str," ");
while (pch != NULL)
{
res.append(pch);
pch = strtok (NULL, " ");
}
}
return 0;
}
It would be great if someone could point to the possible problem.
Following is the cilkscreen report:
Race condition on location 0x33065533d0
write access at 0x3306279fb8: (strtok+0xe8)
read access at 0x3306279ee8: (strtok+0x18)
called by 0x2aaabe1ae379: (_Z15cilkscreen_loopIPFvPvmmEmEQbT_S0_T0_+0xa9)
called by 0x2aaabe1ae90e: (_ZN4cilk13cilk_for_loopEQvPFvPvmmES0_mm+0x15e)
called by 0x4010b1: (_Z9cilk_mainQiiPPc+0xd1)
called by 0x401513: (_ZN4cilk9main_wrapEQiPv+0x53)
called by 0x2aaabe1ad5d1: (_Z20cilk_run_wrapper_intQvPv+0x51)
called by 0x2aaabe1af70a: (__cilkrts_init_helper+0x5)
Race condition on location 0x602a6a
write access at 0x3306279f99: (strtok+0xc9)
read access at 0x3306279f7b: (strtok+0xab)
called by 0x2aaabe1ae379: (_Z15cilkscreen_loopIPFvPvmmEmEQbT_S0_T0_+0xa9)
called by 0x2aaabe1ae90e: (_ZN4cilk13cilk_for_loopEQvPFvPvmmES0_mm+0x15e)
called by 0x4010b1: (_Z9cilk_mainQiiPPc+0xd1)
called by 0x401513: (_ZN4cilk9main_wrapEQiPv+0x53)
called by 0x2aaabe1ad5d1: (_Z20cilk_run_wrapper_intQvPv+0x51)
called by 0x2aaabe1af70a: (__cilkrts_init_helper+0x5)
Race condition on location 0x602a6a
write access at 0x3306279f99: (strtok+0xc9)
write access at 0x3306279f99: (strtok+0xc9)
called by 0x2aaabe1ae379: (_Z15cilkscreen_loopIPFvPvmmEmEQbT_S0_T0_+0xa9)
called by 0x2aaabe1ae90e: (_ZN4cilk13cilk_for_loopEQvPFvPvmmES0_mm+0x15e)
called by 0x4010b1: (_Z9cilk_mainQiiPPc+0xd1)
called by 0x401513: (_ZN4cilk9main_wrapEQiPv+0x53)
called by 0x2aaabe1ad5d1: (_Z20cilk_run_wrapper_intQvPv+0x51)
called by 0x2aaabe1af70a: (__cilkrts_init_helper+0x5)
Race condition on location 0x602a6a
read access at 0x33062795c0: (strlen+0x30)
write access at 0x3306279f99: (strtok+0xc9)
called by 0x2aaabe1ae379: (_Z15cilkscreen_loopIPFvPvmmEmEQbT_S0_T0_+0xa9)
called by 0x2aaabe1ae90e: (_ZN4cilk13cilk_for_loopEQvPFvPvmmES0_mm+0x15e)
called by 0x4010b1: (_Z9cilk_mainQiiPPc+0xd1)
called by 0x401513: (_ZN4cilk9main_wrapEQiPv+0x53)
called by 0x2aaabe1ad5d1: (_Z20cilk_run_wrapper_intQvPv+0x51)
called by 0x2aaabe1af70a: (__cilkrts_init_helper+0x5)
Race condition on location 0x33065533d0
write access at 0x3306279fb8: (strtok+0xe8)
write access at 0x3306279fa7: (strtok+0xd7)
called by 0x2aaabe1ae379: (_Z15cilkscreen_loopIPFvPvmmEmEQbT_S0_T0_+0xa9)
called by 0x2aaabe1ae90e: (_ZN4cilk13cilk_for_loopEQvPFvPvmmES0_mm+0x15e)
called by 0x4010b1: (_Z9cilk_mainQiiPPc+0xd1)
called by 0x401513: (_ZN4cilk9main_wrapEQiPv+0x53)
called by 0x2aaabe1ad5d1: (_Z20cilk_run_wrapper_intQvPv+0x51)
called by 0x2aaabe1af70a: (__cilkrts_init_helper+0x5)
Race condition on location 0x33065533d0
read access at 0x3306279ee8: (strtok+0x18)
write access at 0x3306279fa7: (strtok+0xd7)
called by 0x2aaabe1ae379: (_Z15cilkscreen_loopIPFvPvmmEmEQbT_S0_T0_+0xa9)
called by 0x2aaabe1ae90e: (_ZN4cilk13cilk_for_loopEQvPFvPvmmES0_mm+0x15e)
called by 0x4010b1: (_Z9cilk_mainQiiPPc+0xd1)
called by 0x401513: (_ZN4cilk9main_wrapEQiPv+0x53)
called by 0x2aaabe1ad5d1: (_Z20cilk_run_wrapper_intQvPv+0x51)
called by 0x2aaabe1af70a: (__cilkrts_init_helper+0x5)
6 errors found by Cilkscreen
Cilkscreen suppressed 16 duplicate error messages
Note: When the strtok part was put in a function and called from cilk_for, it gave an
internal compiler error.


