Skip to content

Conversation

@kkysen
Copy link
Contributor

@kkysen kkysen commented May 27, 2025

This reformulates how threading works for memory maps. This gets rid of all of the locks and just uses an atomic counter in exchange for guaranteeing that each thread registers only once at the start (with ia2_thread_metadata_new_for_current_thread).

ia2_thread_metadata_new_for_current_thread is called for the main thread in ia2_start (now that #561 has merged) and in new threads in ia2_thread_begin.

Making this lock-free avoids any potential deadlocks and reentrancy issues, meaning the memory map functions can be called in any context, including in a debugger stopped at any point.

@kkysen kkysen marked this pull request as draft May 27, 2025 13:30
@kkysen kkysen force-pushed the kkysen/memory-maps-better-thread-support branch 3 times, most recently from c9bf2da to 09b7ff4 Compare June 2, 2025 18:53
@ayrtonm ayrtonm self-requested a review June 3, 2025 18:22
@kkysen kkysen marked this pull request as ready for review June 5, 2025 21:52
@kkysen kkysen changed the title (WIP) libia2/memory_maps: redo thread support libia2/memory_maps: improve thread support Jun 5, 2025
@fw-immunant
Copy link
Contributor

Needs a rebase onto main to fix CI.

@kkysen kkysen force-pushed the kkysen/memory-maps-better-thread-support branch from 7cf42ba to 3b9adbf Compare June 10, 2025 00:58
@kkysen kkysen force-pushed the kkysen/memory-maps-better-thread-support branch 2 times, most recently from 234af54 to fceb2e0 Compare June 25, 2025 06:31
@kkysen kkysen force-pushed the kkysen/memory-maps-better-thread-support branch from fceb2e0 to 14cd398 Compare July 7, 2025 18:05
@kkysen kkysen force-pushed the kkysen/memory-maps-better-thread-support branch from 14cd398 to 51929e2 Compare July 15, 2025 03:32
@kkysen kkysen changed the base branch from main to kkysen/memory-maps-move-global-to-INIT_RUNTIME July 28, 2025 08:50
@kkysen kkysen force-pushed the kkysen/memory-maps-better-thread-support branch from 51929e2 to 99a0aa3 Compare July 28, 2025 08:50
@kkysen kkysen changed the title libia2/memory_maps: improve thread support memory_maps: make impl lock-free using atomics Jul 28, 2025
@kkysen kkysen force-pushed the kkysen/memory-maps-better-thread-support branch from 99a0aa3 to 533efc2 Compare July 28, 2025 08:56
@kkysen kkysen force-pushed the kkysen/memory-maps-move-global-to-INIT_RUNTIME branch from 2f746d8 to f3107c2 Compare July 31, 2025 06:29
@kkysen kkysen force-pushed the kkysen/memory-maps-better-thread-support branch from 533efc2 to 1f29699 Compare July 31, 2025 06:29
@kkysen kkysen force-pushed the kkysen/memory-maps-move-global-to-INIT_RUNTIME branch from f3107c2 to e5dcc29 Compare August 4, 2025 09:34
@kkysen kkysen force-pushed the kkysen/memory-maps-better-thread-support branch from 1f29699 to c4e1419 Compare August 4, 2025 09:34
@kkysen kkysen force-pushed the kkysen/memory-maps-move-global-to-INIT_RUNTIME branch from e5dcc29 to 1db4ac5 Compare August 6, 2025 08:02
@kkysen kkysen force-pushed the kkysen/memory-maps-better-thread-support branch from c4e1419 to 77361ec Compare August 6, 2025 08:02
kkysen added 4 commits August 18, 2025 09:48
This reformulates how threading works for memory maps.
This gets rid of all of the locks and just uses an atomic counter
in exchange for guaranteeing that each thread registers only once at the start
(with `ia2_thread_metadata_new_for_current_thread`).

`ia2_thread_metadata_new_for_current_thread`
is called for the main thread in `ia2_start`
and in new threads in `ia2_thread_begin`.

Making this lock-free avoids any potential deadlocks and reentrancy issues,
meaning the memory map functions can be called in any context,
including in a debugger stopped at any point.
@kkysen kkysen force-pushed the kkysen/memory-maps-move-global-to-INIT_RUNTIME branch from 1db4ac5 to 100132e Compare August 18, 2025 16:48
@kkysen kkysen force-pushed the kkysen/memory-maps-better-thread-support branch from 77361ec to a153923 Compare August 18, 2025 16:48
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.

4 participants