# \_\_syncthreads() question

**URL:** <https://forums.developer.nvidia.com/t/syncthreads-question/7245>\
**Category:** CUDA Programming and Performance\
**Created:** [January 14, 2009, 7:51pm UTC](https://forums.developer.nvidia.com/t/syncthreads-question/7245 "2009-01-14T19:51:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blake](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/blake/32/9723_2.png) [@Blake](https://forums.developer.nvidia.com/u/Blake)\
**Post date:** [January 14, 2009, 7:51pm UTC](https://forums.developer.nvidia.com/t/syncthreads-question/7245/1 "2009-01-14T19:51:12Z")

</div>

I have a fairly simple question. I know that it is not safe to use \_\_syncthreads() inside a conditional, but what about this?

```auto
__global__ void foo(int N)

{

  if (threadIdx.x >= N) return;

	// do something

	__syncthreads();

}

```

Thanks!

---

<div class="post-metadata">

**Author:** ![E.D\_Riedijk](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@E.D\_Riedijk](https://forums.developer.nvidia.com/u/E.D_Riedijk)\
**Post date:** [January 14, 2009, 8:06pm UTC](https://forums.developer.nvidia.com/t/syncthreads-question/7245/2 "2009-01-14T20:06:12Z")

</div>

> [@](#):
>
> I have a fairly simple question. I know that it is not safe to use \_\_syncthreads() inside a conditional, but what about this?
> 
> ```auto
> __global__ void foo(int N)
> 
> {
> 
> if (threadIdx.x >= N) return;
> 
> // do something
> 
> __syncthreads();
> 
> }
> 
> ```
> 
> Thanks!

this will deadlock, is the threads with threadIdx.x \>= N will never reach the syncthreads();

But

```auto
__global__ void foo(int N)

{

  if (threadIdx.x <0 N) {

	// do something

  }

	__syncthreads();

}

```

will not deadlock and have the same effect
