I need to achieve following scenario , please help me with this:
- A queue will be maintained, which will contain some objects.
- When an object is inserted in the queue, a timer will be started for that object.
- A signal will be sent whenever an event occurs on that object (the event can be like a timeout, some error etc.).
- The event which occurred for this object will be captured and an object Id will be received. The object Id is required to distinguish the object present in the queue and to take appropriate actions.
My approach which did not work for large number of objects is the following:
- create a thread for each object which will pass an object Id to the
thread_function1(void *object_id);and usesleep()as a timer for that object. - Now for other object I have to do same thing by creating
new thread_function2(void *object_id);The above approach will not work as I wanted this to be dynamic.
Operating system: Linux.
I want to implement this in c++ , I have never implemented this so I need your help and guidance to move forward. Any online tutorial, reference will be of great help. Thanks in advance.