Question Regarding Threads
I'm using VC++ and OpenGL. The question is a little complicated. I have data that needs processing. I get a message to update my screen at regular intervals. When I get this message, I have to draw my screen and finish processing any data left over. This data is incorporated into what I draw. I want to keep my CPU load spread out over time between getting these messages. I could easily just process ALL the data at once every time I get the update message. However, I get these hard spikes in CPU. I have this "clock" thread which gets a signal from hardware. Each time this thread gets a trigger signal, it sends a SetEvent to my data processing thread. My data processing thread uses a WaitOnObject for this signal. The clock thread is set to be time critical because it uses a physical device to get its signal. The data process thread is set to normal. Sorry for huge buildup. The problem I have is when I get the render screen message. When I get it, I have only processed a quarter of my data. Yet, the "clock" thread has signaled (SetEvent) to all the data. I was given more signals to process data than actual data processed. I tried setting both threads to time critical, but it didn't seem to help. Thanks for any help. I know it's strange problem.
ResetEvent, SetEvent, etc should work fine for any thread sync that you need. In fact, it's what I use exclusively.
Are you accessing this data asychronously some how?
Critical sections may also suit your needs for making any/all functions thread safe.
This would be good for making a singleton class available to the scope of all threads.
By encasing function bodies inside of critical section entrance/exit code, any number of threads can call that function.
If the critical section has been entered by another thread, the OS queues up all function calls from any other thread.
As the original thread exits the critical section, the OS resumes the next thread in the queue. Repeat until all threads have had their chance at running that function's code statements.
There is a critical section function which allows you to abort after a certain waiting period, but I've never looked into it.
Are you accessing this data asychronously some how?
Critical sections may also suit your needs for making any/all functions thread safe.
This would be good for making a singleton class available to the scope of all threads.
By encasing function bodies inside of critical section entrance/exit code, any number of threads can call that function.
If the critical section has been entered by another thread, the OS queues up all function calls from any other thread.
As the original thread exits the critical section, the OS resumes the next thread in the queue. Repeat until all threads have had their chance at running that function's code statements.
There is a critical section function which allows you to abort after a certain waiting period, but I've never looked into it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement