Improve WASI thread id allocator to reuse identifiers#1809
Conversation
26f72a6 to
3b4ff81
Compare
|
I'm doing some additional refactoring to have both |
3b4ff81 to
7e32b7d
Compare
| if (avail_tids.pos == 0) { // Resize stack and push new thread ids | ||
| uint32 old_size = avail_tids.size; | ||
| uint32 new_size = avail_tids.size * 2; | ||
| if (new_size / 2 != avail_tids.size) { |
There was a problem hiding this comment.
[minor] you might just compare old_size with the new_size to avoid additional division.
There was a problem hiding this comment.
I used the division to make it similar to L54. I'm not sure a simple comparison would work for L54 (maybe when overflowing/wrapping the result can be bigger than the initial value?)
There was a problem hiding this comment.
yes, one way to detect integer overflow here is to check if new_size < avail_tids.size. It's not a major callout though.
7e32b7d to
6c25253
Compare
| goto return_id; | ||
| } | ||
| int32 *tmp = | ||
| (int32 *)wasm_runtime_realloc(avail_tids.ids, realloc_size); |
There was a problem hiding this comment.
Should I get rid of it? I put it (and same for the malloc) for consistency with the rest of the codebase
6c25253 to
867954a
Compare
|
@wenyongh fixed the conflicts, I think we can merge it now |
…ytecodealliance#1809) This PR allows reusing thread ids once they are released. That is done by using a stack data structure to keep track of the used ids. When a thread is created, it takes an available identifier from the stack. When the thread exits, it returns the id to the stack of available identifiers.
At the moment, when created, a thread receives an incremental number as an identifier.
This PR allows reusing thread ids once they are released. That is done by using a stack data structure to keep track of the used ids.
When a thread is created, it takes an available identifier from the stack. When the thread exits, it returns the id to the stack of available identifiers.