# CUDA race conditions

**URL:** <https://discourse.julialang.org/t/cuda-race-conditions/109458>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 30, 2024, 4:21pm UTC](https://discourse.julialang.org/t/cuda-race-conditions/109458 "2024-01-30T16:21:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![trasor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/trasor/32/213340_2.png) [@trasor](https://discourse.julialang.org/u/trasor)\
**Post date:** [January 30, 2024, 4:21pm UTC](https://discourse.julialang.org/t/cuda-race-conditions/109458/1 "2024-01-30T16:21:49Z")

</div>

Hi together, i try to paralize some of my code with Cuda kernels, but somehow produced race conditions:

The kernel looks somewhat like:

function updateB!(inputs)  
x = threadIdx().x + (blockIdx().x-1) \* blockDim().x  
if x \>= 2 && x \<= nx-2  
dA[x] = (A[x+1] - A[x])  
B[x] += scalar \* dA[x]  
end  
return nothing  
end

it has probably something to do that i update B[x] at the end, and each thread try to write something into that array. However, i was not able to find a solution for this
