05-28-2024, 01:31 PM
@justsomeguy just some notes from looking at your code:
1. Don't pass `tdata` on the stack to the thread. You should useĀ something like `malloc()` to allocate it because you don't know when the other thread will actually start using it, it could happen after invokeWorker returns.
2. Your mutexes aren't doing anything because each thread has its own. You should also initialize them before starting the thread.
3. Because there's no lock protecting access to the images, the main thread could end up reading from the image while a worker thread has only written half a color.
4. I wouldn't declare the`dly` integer inside the SUB.
5. Calling `resetWorker` from the worker thread is not safe.
I would also recommend putting the worker thread `SUB` inside of a `$CHECKING:OFF` block, that will prevent QB64 from inserting the error handling logic into the code for your thread.
1. Don't pass `tdata` on the stack to the thread. You should useĀ something like `malloc()` to allocate it because you don't know when the other thread will actually start using it, it could happen after invokeWorker returns.
2. Your mutexes aren't doing anything because each thread has its own. You should also initialize them before starting the thread.
3. Because there's no lock protecting access to the images, the main thread could end up reading from the image while a worker thread has only written half a color.
4. I wouldn't declare the`dly` integer inside the SUB.
5. Calling `resetWorker` from the worker thread is not safe.
I would also recommend putting the worker thread `SUB` inside of a `$CHECKING:OFF` block, that will prevent QB64 from inserting the error handling logic into the code for your thread.