ChrisOS Research ProjectOperating systems · language systems · graphics · machine emulation
DOCUMENTATION ARCHIVEMAIN BRANCH
ChrisOS/Source reference: APPS/THREADS/COUNT.CC

Source reference: APPS/THREADS/COUNT.CC

Deterministic source record. The complete textual file is reproduced below; this page does not replace architectural interpretation in the authored chapters.

File identity

Field Value
Path APPS/THREADS/COUNT.CC
Lines 31
Bytes 442
SHA-256 9c59c781b031c39c4e172c0a9daa3389e5ad60bf5eef789db2585a87de911617
ChrisOS revision da3df29cb397932c43d32373871fb9380e688ade

Detected syntactic dependencies

Line Include
— No preprocessor include detected.

Detected symbols

Line Symbol
4 worker
15 main

Complete source

The following block is the complete textual file at the recorded revision. No lines are elided, abbreviated or paraphrased.

int g_n;
int g_lock;

void worker(int arg) {
  int i;
  i = 0;
  while (i < 1000) {
    mtx_lock(g_lock);
    g_n = g_n + 1;
    mtx_unlock(g_lock);
    i = i + 1;
  }
}

void main() {
  int id;
  int seen;
  g_n = 0;
  g_lock = 1;
  id = thrd_create(worker, 0);
  seen = 0;
  while (seen < 1000) {
    mtx_lock(g_lock);
    seen = g_n;
    mtx_unlock(g_lock);
  }
  thrd_join(id);
  viewport(160, 80);
  text(8, 8, "threads", 0x00FFFFFF);
}

Role of this record

The atlas guarantees file-by-file traceability. Responsibility, invariants, ownership, concurrency, security, performance and subsystem interactions belong in authored chapters and must cite this file when applicable.

Document record ID: source-9c59c781b031c39c Reviewed source: da3df29cb397 Class: generated-source-reference