Skip to content

Commit

Permalink
tmp: avoid dead lock in callback
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhuyan committed Apr 11, 2024
1 parent 419550b commit 25cd751
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions c_src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,20 @@ erlfdb_future_cb(FDBFuture* fdb_future, void* data)
if(enif_thread_type() == ERL_NIF_THR_UNDEFINED) {
caller = NULL;
} else {
enif_mutex_lock(future->lock);
caller = future->pid_env;
}

enif_mutex_lock(future->lock);


if(!future->cancelled) {
msg = T2(future->msg_env, future->msg_ref, ATOM_ready);
enif_send(caller, &(future->pid), future->msg_env, msg);
}

enif_mutex_unlock(future->lock);
if (caller) {
enif_mutex_unlock(future->lock);
}

// We're now done with this future which means we need
// to release our handle to it. See erlfdb_create_future
Expand Down

0 comments on commit 25cd751

Please sign in to comment.