I want to run a thread in native code that can post data to managed code.
So my first question is: how do I start a thread in native code. The thread should run in parallel with the managed code…
Second question is, how can I post data to the managed code, or should I use a polling method initiated from managed code?
And can I let managed threads running during the native Task? (there are only small pieces that shouldn’t get interrupted, but therefore I could Disable and Enable global interrupts)
My task would involve reading and writing serial data. But I’ll try to create an interrupt driven statemachine. That way the overhead will be reduced to almost zero
IMO, GHI needs to do a write up on cost (instructions, time, etc) of transition to native and back. At least in .Net a managed to native context switch is a relatively expensive operation in each direction. Marshalling, context switch, etc takes many instructions. Depending on what your doing, the Tax could overcome the benefits.
Would seem to need a queue here that lives in both layers - half-and-half. Produce from native side and pop from managed side. Can you Set .Net events (i.e. autoreset, etc) from native side? If possible, a sample on this method would be cool. As you limit the native savings if you can’t cache and have to ping-pong on each data notification. At least buffer N element array or time.