/*
 * Copyright ©2026 Soham Pardeshi. All rights reserved.
 * Permission is hereby granted to students registered for University of
 * Washington CSE 333 for use solely during Summer Quarter 2026 for
 * purposes of the course. No other use, copying, distribution, or
 * modification is permitted without prior written consent. Copyrights
 * for third-party components of this work must be honored. Instructors
 * interested in reusing these course materials should contact the author.
 */

// Hazard (lecture demo), not a crash: a global is shared mutable state.
// g_count lives in .data as one cell that any function can change, which
// makes its value hard to reason about (and unsafe once threads share it).
#include <stdio.h>
#include <stdlib.h>

int g_count = 0;   // one global, in .data

void Tick(void) {
  g_count++;
}

int main(int argc, char* argv[]) {
  Tick();          // g_count -> 1
  g_count = 100;   // changed from afar
  Tick();          // g_count -> 101
  printf("%d\n", g_count);  // who set g_count? hard to reason
  return EXIT_SUCCESS;
}