C
C#5mo ago
Chik3r

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
6 Replies
Jimmacle
Jimmacle5mo ago
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?
while (!ErrorDataPtr[baseOffset - ImgWidth - 1].IsReady)
{
...
}
while (!ErrorDataPtr[baseOffset - ImgWidth - 1].IsReady)
{
...
}
Chik3r
Chik3r5mo ago
because i was using unsafe stuff and got stuck thinking about pointers idk why i didnt just use an array
Jimmacle
Jimmacle5mo ago
common problem :LULW:
Chik3r
Chik3r5mo ago
this works ty for the help
Jimmacle
Jimmacle5mo ago
: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
Chik3r
Chik3r5mo ago
its only a tiny wait my simple attempt at parallelizing floyd dither
Want results from more Discord servers?
Add your server