Main Site Documentation

Locking


#1

I read that event handlers execute in a “hidden” thread inside NETMF. If a data structure is shared between a user thread and and event handler is locking needed?

Thanks,
Wayne


#2

Yes!


#3

Always?
Some say: it depends.


Is it a special case in NETMF?


#4

@ RoSchmi - To quote Gilbert and Sullivan…

[quote]What, never?
No, never!
What, never?
Well, hardly ever…[/quote]

In general, if any thread modifies a shared resource, then locking should be used by all threads. A readonly resource does not need to be locked.

If one has a good understanding of their application and knows about thread usage and locking, then there might be situations where locking is not required. But, if someone asks if locking is required, with shared threads, I always say yes.


#5

Lol, that’s good.