Document the mutex shenanigans used to implement block until ready

This commit is contained in:
A.J. Beamon 2018-10-08 15:17:37 -07:00
parent f994664130
commit b3e271bc2a
1 changed files with 7 additions and 0 deletions

View File

@ -87,6 +87,13 @@ func fdb_future_block_until_ready(f *C.FDBFuture) {
return
}
// The mutex here is used as a signal that the callback is complete.
// We first lock it, then pass it to the callback, and then lock it
// again. The second call to lock won't return until the callback has
// fired.
//
// See https://groups.google.com/forum/#!topic/golang-nuts/SPjQEcsdORA
// for the history of why this pattern came to be used.
m := &sync.Mutex{}
m.Lock()
C.go_set_callback(unsafe.Pointer(f), unsafe.Pointer(m))