Hi, I implemented the Bakery Alg (see below) to solve shared memory synchronization among threads:

http://nob.cs.ucdavis.edu/classes/ecs150-1…ync-bakery.html

But this leads to crash.

Do you have suggestions on that? thanks!

```
//tx is thread id
s_choosing(tx) = 0;
s_number(tx) = 0;
int rId;
int tmpMax;
...if(f(tx))
s_choosing(tx) = 1;
tmpMax = s_number(0);
for(i = 0; i < blockDim.x; ++i)
{
if(tmpMax < s_number(i))
tmpMax = s_number(i);
}
++tmpMax;
s_number(tx) = tmpMax;
s_choosing(tx) = 0;
for (i = 0; i < blockDim.x; ++i)
{
while(s_choosing(i) == 1);
while((s_number(i) != 0) &&
((s_number(i) < s_number(tx)) || ( (s_number(i) == s_number(tx)) && (i < tx) )) );
}
//enter critical section
func(tx, s_cnt); ++s_cnt;
s_number(tx) = 0;
//leave section
```