Basically i have multi threads that adds data into a queue via SQLite. I have another one thread that pulls them and process them one at a time (too much resource to do multiple at once). The processing thread does this:
- pull data from DB
- foreach { proccess }
- if count == 0 { thread.suspend() } (waken by thread.resume())
- repeat
my worker thread does:
- Validates data
- Inserts into DB
- call Queue.Poke(QueueName)
When I poke it, if the thread is suspended I .resume()
it.
What I am worried about is if the process thread sees count==0
, my worker inserts and pokes then my process continues down the if and sleeps. It won't realize there is something new in the DB.
How should I write this in such a way that I won't have a race condition.