mercredi 16 août 2017

multithreaded one read one write time_t

I'm writing a multithreaded application that have 2 threads. One of the threads receives data from a queue and aggregates it and the other one send the aggregated data to a server.

I want to be able to know the last time that a data was received so I use time_t last_data = time(NULL) to get the correct time on each event (I dont need it to be super accurate but I need it to be fast) and then the other send this value with the aggregated data.

My questions are:

  1. Do I have to synchronize this even if this is not very important that I get the most recent update?
  2. I tested it with std::atomic<time_t> and it seems to have some performance issues, is there any other faster way?
  3. What would be the worst case that can happen if I will not synchronize the read/write?
  4. Is there a faster way to get the current time then time(NULL) (don't have to be super accurate)?

Aucun commentaire:

Enregistrer un commentaire