[AGENT++] can i use two thread, one to update data, the other processrequest?

Frank Fock fock at agentpp.com
Thu Nov 14 16:45:33 CET 2013


Hi,

Yes, you can do it like that, but you have to lock the Mib instance and
the MibEntry instances before you update them in the following scheme:

do_update() {
mib->lock_mib();
MibEntry entry = find_entry("query");
entry->start_synch();
// you can now unlock if you do not need to search another MibEntry
mib->unlock();

entry->do_update(...);

entry->end_synch();
}

Best regards,
Frank



Am 11.11.2013 10:44, schrieb hyznull:
> hi
>
> i want to make 2 thread,threadProcess is wait to process request,and the other threadUpdate will clear the content,and add the row again after sleep function.can i use this way to update my data?
>
>   
>
> void threadProcessReqest
>
> {
>
>      while (1)
>      {
>          req = reqList->receive(10);
>
>          if (req)
>
>          {
>
>              mib->process_request($req);
>          }
>      }
>
> }
>
>   
>
> void threadUpdate
>
> {
>
>      MibTableInstance->content.clearAll();
>
>   
>
>      for(int i = 0;i < GetSizeFromMem();i++)
>
>      {
>
>           MibTableRow* r = MibTableInstance->add_row(index_inner);
>           r->get_nth(0)->replace_value(new SnmpInt32(/*new value1*/));
>
>           r->get_nth(1)->replace_value(new SnmpInt32(/*new value2*/));
>
>      }
>
>      sleep(1000)
>
> }
>
>   
>
> int main()
>
> {
>
>   //step1:init snmp & agent
>
>   //step2:Create thread bind to threadUpdate
>
>   //step3:Create thread bind to threadProcessReqest
>
>   //step4:wait to exit
>
>   return 0;
>
> }
>
> Thank you
>   		 	   		
> _______________________________________________
> AGENTPP mailing list
> AGENTPP at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/agentpp

-- 
---
AGENT++
Maximilian-Kolbe-Str. 10
73257 Koengen, Germany
https://agentpp.com
Phone: +49 7024 8688230
Fax:   +49 7024 8688231



More information about the AGENTPP mailing list