main.cpp 828 Bytes
Newer Older
1 2 3 4 5
#include <sys/types.h>
#include <unistd.h>
#include <fstream>
#include <sstream>
#include <string>
6

7 8
#include <mutex>
#include "tsan_support.h"
9

10 11
using namespace std;

12 13 14 15 16 17 18 19 20 21 22 23
long count_memory_mappings() {
  pid_t my_pid = getpid();
  ifstream proc_file{"/proc/" + to_string(my_pid) + "/maps"};

  string line;
  long line_count{0};
  while (getline(proc_file, line)) {
    line_count++;
  }

  return line_count;
}
24

25
int main() {
26
  mutex mut;
27 28

  int count = 0;
29
  while (true) {
30 31 32 33 34 35 36 37 38
    printf("iteration: %d, mappings: %ld\n", count++, count_memory_mappings());
    void *main_fiber = __tsan_get_current_fiber();
    void *other_fiber = __tsan_create_fiber(0);
    __tsan_switch_to_fiber(other_fiber, 0);
    mut.lock();
    mut.unlock();
    __tsan_switch_to_fiber(main_fiber, 0);
    __tsan_destroy_fiber(other_fiber);

39
  }
40

41
  return 0;
42
}