Skip to content

Instantly share code, notes, and snippets.

@portante
Created March 20, 2017 19:07
Show Gist options
  • Select an option

  • Save portante/b80c815efd3b319f206cd939c63eec10 to your computer and use it in GitHub Desktop.

Select an option

Save portante/b80c815efd3b319f206cd939c63eec10 to your computer and use it in GitHub Desktop.
An example code flow for seeding
seeded_state = UNSEEDED;
lock = Lock();
syncing = Sync();
process() {
if (seeded_state == SEEDED) {
continue;
} else {
lock.lock();
try {
if (seeded_state == UNSEEDED) {
seeded_state = SEEDING;
lock.unlock();
seed_searchguard();
lock.lock();
seeded_state = SEEDED;
syncing.signalAll();
}
else {
while (seeded_state != SEEDED) {
syncing.await(TIMEOUT);
}
}
}
finally {
lock.unlock();
}
}
assert seeded_state == SEEDED;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment