Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Events and locking in thread  RSS feed

 
skarlos
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends,
I need help wrt Event in thread,
i have one thread A_Th and in that i'm doing some processing so i want to implement the class for Event so that when event is fired some notification is given to A_Th so that he can call other thread B_th for let say readint the data from array.and give it back to A_Th afterwords,
so how i supposed to achive this using Event and Locks

Karlos
 
Sabarish Sasidharan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To get started, wait() and notify() can be used to make this happen. I hope this is what u want. The A_Th should call wait() on the Event instance. As soon as the event occurs then the Event instance should call notify() which will bring back A_Th to ready state.(not accurate, but to be simpler). Then the A_Th can do what ever it wants to handle the event.
Pls note that i have assumed that some variables have been already initialized properly. To give just an idea ...

But which thread of those waiting will actually be notified can't be predicted and hence each thread upon clearing from wait should check for the state it expects the Event instance to be in and if it is not so then go back to waiting state.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!