Waiting until struct is modified from another thread
Hi, I have an array of structs which contain a
bool
that is modified from thread A. In thread B, I have to wait until the value of struct at index N becomes true
before continuing. This works using pointers (see image), however I wanted to know if there was a better/safer way to do it?
Assuming I can only do this with pointers, how would performance be affected from pinning the array using GCHandle.Alloc
(or some other method) for a long period time? Is it better to keep the array pinned or to pin/unpin every frame?![No description](https://cdn.answeroverflow.com/1230649189193486357/image.png)
6 Replies
you're using pointers specifically to avoid repeatedly indexing into the array, yeah?
is that actually a performance issue in your code?
why aren't you doing this?
because i was using unsafe stuff and got stuck thinking about pointers
idk why i didnt just use an array
common problem :LULW:
this works
ty for the help
:pepeok:
i would also recommend looking into using some kind of synchronization other than spin waiting, unless this isn't supposed to be waiting for long
its only a tiny wait
my simple attempt at parallelizing floyd dither