Created
January 9, 2015 13:54
-
-
Save ChristianKienle/4f5c95dad21072348481 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pseudo Code: | |
// Create table: | |
CREATE TABLE LOCK (who Text, locked Bool); | |
// You have to use PGCKit to be able to query this table and create instances of: | |
struct Lock { | |
NSString *who; | |
BOOL locked; | |
} | |
// Let's assume Process A wants to do something critical: | |
doSomethingCiritial() { | |
// 1. Get the current lock | |
Lock l = getLock() | |
if(l.locked == NO) { | |
l.locked = YES; | |
l.who = getIDFromUserDefaults() | |
db.save(l) | |
} | |
// Do the actual work | |
criticalStuff() | |
// When done: | |
l.who = NULL; | |
l.locked = NO; | |
db.save(l) | |
} | |
// Lets assume Process A crashes before it was able to unlock the lock… | |
cloudAppDidFinishLaunching() { | |
// Get Lock | |
Lock l = db.getLock(); | |
if(l.locked && l.who == getIDFromUserDefaults()) { | |
// The lock is still in place AND it was created by the current process | |
// unlock: | |
l.locked = NO; | |
l.who = NULL: | |
db.save(l); | |
} else { | |
// normal work | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment