Skip to content

Commit

Permalink
std/sync: refactor documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Jan 17, 2025
1 parent fbb7794 commit b7f0acc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion std/sync/cond.jule
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Cond {
//
// self.Lock()
// for !condition() {
// self.Wait()
// self.Wait()
// }
// ... make use of condition ...
// self.Unlock()
Expand Down
28 changes: 14 additions & 14 deletions std/sync/once.jule
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,34 @@ impl Once {
ret Once{}
}

// Calls the function f if and only if do is being called for the
// Calls the function f if and only if Do is being called for the
// first time for this instance of Once. In other words, given
//
// let once = Once{}
// once := Once{}
//
// if once.do(f) is called multiple times, only the first call will invoke f,
// if once.Do(f) is called multiple times, only the first call will invoke f,
// even if f has a different value in each invocation. A new instance of
// Once is required for each function to execute.
//
// do is intended for initialization that must be run exactly once. Since f
// Do is intended for initialization that must be run exactly once. Since f
// is niladic, it may be necessary to use a function literal to capture the
// arguments to a function to be invoked by do:
// arguments to a function to be invoked by Do:
//
// config.once.do(func() { config.init(filename) })
// config.once.Do(func() { config.init(filename) })
//
// Because no call to do returns until the one call to f returns, if f causes
// do to be called, it will deadlock.
// Because no call to Do returns until the one call to f returns, if f causes
// Do to be called, it will deadlock.
//
// If f panics, do considers it to have returned; future calls of do return
// If f panics, Do considers it to have returned; future calls of Do return
// without calling f.
fn Do(self, f: fn()) {
// Note: Here is an incorrect implementation of do:
// Note: Here is an incorrect implementation of Do:
//
// if self.done.CompareSwap(0, 1) {
// f()
// }
// if self.done.CompareSwap(0, 1) {
// f()
// }
//
// do guarantees that when it returns, f has finished.
// Do guarantees that when it returns, f has finished.
// This implementation would not implement that guarantee:
// given two simultaneous calls, the winner of the cas would
// call f, and the second would return immediately, without
Expand Down

0 comments on commit b7f0acc

Please sign in to comment.