#include "usg_common.h" #define THREADS 4 typedef struct shm_packet_t { int key; size_t size; void * buf; char uuid[64]; int action; } shm_packet_t; void *_run_(void *arg) { std::map * amap = (std::map *)arg; std::map::iterator iter; iter = amap->find(2); while( iter != amap->end() ) { amap->erase(iter); iter = amap->find(2); sleep(1); } } int main() { int i; pthread_t tids[THREADS]; std::map * amap = new std::map; for (i = 0; i < THREADS; i++) { pthread_create(&tids[i], NULL, _run_, (void *)&amap); } shm_packet_t pack; pack.key = 2; while(true) { sleep(1); amap->insert({2, pack}); } for (i = 0; i < THREADS; i++) { if (pthread_join(tids[i], NULL) != 0) { perror(" pthread_join"); } } }