diff --git a/bindings/go/src/fdb/futures.go b/bindings/go/src/fdb/futures.go index c86441254e..f3541f0689 100644 --- a/bindings/go/src/fdb/futures.go +++ b/bindings/go/src/fdb/futures.go @@ -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))