Problem
I'm trying to create an CUDA application that is well integrated with .net. The design goal is to have several CUDA functions that can be called from managed code. Data should also be able to persist on a device between function calls, so that it can be passed to multiple CUDA functions.
It is of importance that each individual piece of data is only accessed by a single OS thread (as required by CUDA)
My Strategy
I'm wrapping CUDA functionalities and device pointers in Managed C++ code. A CUDA device pointer can be wrapped in a DevicePointer
class written in MC++. If the class tracks which thread it is using, it can enforce that only a single thread can access the CUDA device pointer.
I'll then design the program so that only a single thread would attempt to access any given piece of data.
Where I need help
I've done some research, and read about the distinction between managed threads and OS threads. It seems that there is, in general, a many to many relationship between the two.
This means that even though I'm only using a single managed thread, it could switch OS threads, and I'll loose access to a device pointer.
Is there any way to force the CLR to not move a managed thread between OS threads?