Skip to content

Instantly share code, notes, and snippets.

@diogovk
Last active August 9, 2016 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diogovk/e58f4be7cd7328d16cd2dbe040737448 to your computer and use it in GitHub Desktop.
Save diogovk/e58f4be7cd7328d16cd2dbe040737448 to your computer and use it in GitHub Desktop.
// program_start
fd_log = open("logfile.log")
fn log(msg) {
fd_log.write(msg)
fd_log.flush()
}
log("something happened")
// program ends and all open file descriptors are closed by the OS
##############################################
// program_start do nothing
fn log(msg) {
// this function absolutely must be SYNC, otherwize we can end up opening the same file many times!
fd_log = open("logfile.log")
try {
fd_log.write(msg);
} finally {
fd_log.close()
}
}
log("something happened")
// program ends
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment