Monty Taylor wrote:
>
> This is not safe. You cannot remove elements from a vector while
> iterating through an active iterator. You can do this though:
>
> class alarm_if
> {
> time_t alarm_time;
> public:
> alarm_if(time_t now) : alarm_time(now);
> inline bool operator(ALARM * current_alarm)
Oops. That should be inline bool operator() (ALARM* current_alarm). Sorry.
> {
> if (current_alarm->expire_time <= now)
> {
> current_alarm->alarmed= 1; /* Info to thread */
> if (pthread_equal(current_alarm->thread,alarm_thread) ||
> pthread_kill(current_alarm->thread, thr_client_alarm))
> {
> return true;
> }
> else
> {
> current_alarm->expire_time= next;
> }
> }
> return false;
> }
> }
>
> alarm_stack.erase(remove_if(alarm_stack.begin(), alarm_stack.end(),
> alarm_if(now),
> alarm_stack.end());
>
>
>
> (note - untested - just off the top of my head)
>
> Monty
>
_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help : https://help.launchpad.net/ListHelp