cudaGL + multithreading?

Hi,

I have a problem when using CUDA+OpenGL interop and mutli-threading.

Pseudocode:

void Thread()

{

  InitGLContext();

  cutilSafeCall( cudaSetDevice(0) );

  cutilSafeCall( cudaGLSetGLDevice(0) );

CreateTexture(); // initializes OpenGL texture (float)

  cudaGraphicsGLRegisterImage(...) // returns error for second thread

}

void main()

{

  int numThreads = 2;

  CreateThreads(2, Thread);

}

It is not working if numThreads >= 2, no problem for 1 thread.

Card: GeForce GTX 275

CUDA version: 3.0

Driver version: 197.45

Thanks for help.

Martin

Seems that only one thread can create a valid CUDA context with OpenGL interop :confused:
I tried CUDA driver API and the cuGLCtxCreate function returns CUDA_SUCCESS only for the first executed thread, otherwise CUDA_ERROR_OUT_OF_MEMORY .

No problem with several running cudaGL processes…