Skip to content

Fix multi-threading issues#2013

Merged
wenyongh merged 8 commits intobytecodealliance:mainfrom
wenyongh:implement_atomic_fence
Mar 8, 2023
Merged

Fix multi-threading issues#2013
wenyongh merged 8 commits intobytecodealliance:mainfrom
wenyongh:implement_atomic_fence

Conversation

@wenyongh
Copy link
Collaborator

@wenyongh wenyongh commented Mar 7, 2023

  • Implement atomic.fence to ensure a proper memory synchronization order
  • Destroy exec_env_singleton first in wasm/aot deinstantiation
  • Fix detach thread in thread_manager_start_routine
  • Fix duplicated lock cluster->lock in wasm_cluster_cancel_thread
  • Add lib-pthread and lib-wasi-threads compilation to Windows CI

wenyongh added 3 commits March 7, 2023 14:34
Merge bytecodealliance:main into wenyongh:implement_atomic_fence
@wenyongh wenyongh changed the title Fix multi-threading issues [WIP] Fix multi-threading issues Mar 7, 2023
wasm_cluster_thread_exited(exec_env);
#endif

os_mutex_lock(&cluster_list_lock);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this lock required by wasm_cluster_del_exec_env?
Had better update the comment for wasm_cluster_del_exec_env:

/* The caller should lock cluster->lock and 
    cluster_list_lock for thread safety */

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this lock here is to lock

if (exec_env->wait_count == 0 && !exec_env->thread_is_detached) {
    ...
}

wasm_cluster_del_exec_env only needs to lock cluster->lock

return 0;
}

os_mutex_lock(&exec_env->cluster->lock);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had better add comment for this function to ask the caller to ensure thread safety

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the code here since clusters_have_exec_env will lock again, which leads to hang.

@wenyongh wenyongh changed the title [WIP] Fix multi-threading issues Fix multi-threading issues Mar 8, 2023
@xujuntwt95329
Copy link
Collaborator

LGTM

@wenyongh wenyongh merged commit f279ba8 into bytecodealliance:main Mar 8, 2023
@wenyongh wenyongh deleted the implement_atomic_fence branch March 8, 2023 09:00
vickiegpt pushed a commit to vickiegpt/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
- Implement atomic.fence to ensure a proper memory synchronization order
- Destroy exec_env_singleton first in wasm/aot deinstantiation
- Change terminate other threads to wait for other threads in
  wasm_exec_env_destroy
- Fix detach thread in thread_manager_start_routine
- Fix duplicated lock cluster->lock in wasm_cluster_cancel_thread
- Add lib-pthread and lib-wasi-threads compilation to Windows CI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants