fix potential deadlock in block.c
@@ -1030,7 +1030,6 @@ static void *work_thread(void *arg)
}
pthread_mutex_lock(&block_mutex);
- pthread_mutex_lock(&g_transport_mutex);
if (g_xdag_state == XDAG_STATE_REST) {
g_xdag_sync_on = 0;
@@ -1057,7 +1056,9 @@ static void *work_thread(void *arg)
conn_time = sync_time = 0;
goto begin;
- } else if (t > (g_xdag_last_received << 10) && t - (g_xdag_last_received << 10) > 3 * MAIN_CHAIN_PERIOD) {
+ } else {
+ pthread_mutex_lock(&g_transport_mutex);
+ if (t > (g_xdag_last_received << 10) && t - (g_xdag_last_received << 10) > 3 * MAIN_CHAIN_PERIOD) {
g_xdag_state = (g_light_mode ? (g_xdag_testnet ? XDAG_STATE_TTST : XDAG_STATE_TRYP)
: (g_xdag_testnet ? XDAG_STATE_WTST : XDAG_STATE_WAIT));
conn_time = sync_time = 0;
@@ -1083,13 +1084,14 @@ static void *work_thread(void *arg)
g_xdag_state = (g_xdag_testnet ? XDAG_STATE_STST : XDAG_STATE_SYNC);
}
}
+ pthread_mutex_unlock(&g_transport_mutex);
+ }
if (!g_light_mode) {
check_new_main();
}
struct block_internal *ours = ourfirst;
- pthread_mutex_unlock(&g_transport_mutex);
pthread_mutex_unlock(&block_mutex);
xdag_show_state(ours ? ours->hash : 0);
