Skip to content

Conversation

@xujuntwt95329
Copy link
Collaborator

The debug_instance_list is not protected by mutex, and the debug instance use
the length of this list as its id. If several threads create debug instance at
the same time, they may get duplicate ids. This patch add mutex to protect this
list

The debug_instance_list is not protected by mutex, and the debug instance use
the length of this list as its id. If several threads create debug instance at
the same time, they may get duplicate ids. This patch add mutex to protect this
list
static uint32 current_instance_id = 1;

static uint32
allocate_instance_id()
Copy link
Collaborator

Choose a reason for hiding this comment

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

how about GCC atomic builtins?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I‘ve also considered this, but I concern about the compiler compatibility. The GCC atomic builtins are optional features so there may be some compiler who doesn't implement it.

Also, in my opinion, these codes are not on the critical path, the mutex lock should not raise performance issues

@wenyongh how do you think about this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Should not use the optional function which might lead to link error in some platform or compiler. Normally here we should use the API provided by platform layer.

memset(engine, 0, sizeof(WASMDebugEngine));

if (os_mutex_init(&engine->instance_list_lock) != 0) {
LOG_ERROR("WASM Debug Engine error: failed to init mutex");
Copy link
Contributor

Choose a reason for hiding this comment

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

Should free engine before return NULL

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@wenyongh wenyongh merged commit 9b0b33e into bytecodealliance:main Nov 25, 2021
vickiegpt pushed a commit to vickiegpt/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
…ecodealliance#847)

The debug_instance_list is not protected by mutex, and the debug instance uses
the length of this list as its id. If several threads create debug instance at the
same time, they may get duplicated/same ids. This patch adds mutex to protect
this list.
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