cudaDeviceSynchronize() can cause program hanging

when I run a cuda program. All the cudaDeviceSynchronize() statements in the cuda program can cause program hanging. I guess maybe cudaDeviceSynchronize() has something special in cuda11.2 for gtx2060? the One of example is as follows:
void MatrixDevice::memAlloc()
{
if (buffer_ != NULL && fr_) {
checkCudaErrors(cudaFree(buffer_));
buffer_ = NULL;
}

checkCudaErrors(cudaMalloc(&buffer_, sizeof(double) * rows_ * cols_ * offset_));
checkCudaErrors(cudaMemset(buffer_, 0, sizeof(double) * rows_ * cols_ * offset_));
checkCudaErrors(cudaDeviceSynchronize());
fr_ = true;

}
the program hangs in the " checkCudaErrors(cudaDeviceSynchronize());" and doesn’t go on running the next statement. I don’t know why.
hardware: i7-10875H, ram 16G, display card gtx2060
os: ubuntu18.04
and cuda 11.2
Could someone know why?Thank you very much!