Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fir/time/interval_meter.h>
- #include <pthread.h>
- #include <semaphore.h>
- #include <unistd.h>
- struct Sync {
- sem_t sem_;
- Sync() {
- sem_init(&sem_, 0, 0);
- }
- };
- void* thread_measure(void*p) {
- Sync *s = (Sync*)p;
- fir::time::IntervalMeter imeter;
- while(1) {
- sem_wait(&s->sem_);
- auto ms = imeter.getMs();
- if ( ms > (((1000000/30))/1000) ) {
- std::cout << "ms " << ms;
- }
- }
- return nullptr;
- }
- int main(void) {
- Sync sync;
- pthread_t thread_id;
- pthread_create(&thread_id, nullptr, thread_measure, &sync);
- // thread ticks
- while(1) {
- usleep(1000000/30);
- sem_post(&sync.sem_);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement