Give each element a serial number #22

Merged
glen merged 6 commits from element-serial into main 2024-11-22 02:25:11 +00:00
Collaborator

Address issue #20 by giving each Element a serial number, which identifies it uniquely (until the serial number wraps around). The serial number assigned by the Element::new constructor.

For future thread-safety, the next serial number is stored in a static atomic variable (assembly::NEXT_ELEMENT_SERIAL), as suggested in this StackOverflow answer. Since the overhead for keeping track of memory ordering should be minimal, we're using the strongest available ordering: sequentially consistent.

Address issue #20 by giving each `Element` a serial number, which identifies it uniquely (until the serial number wraps around). The serial number assigned by the `Element::new` constructor. For future thread-safety, the next serial number is stored in a static atomic variable (`assembly::NEXT_ELEMENT_SERIAL`), as suggested in [this StackOverflow answer](https://stackoverflow.com/a/32936288). Since the overhead for keeping track of memory ordering should be minimal, we're using the strongest available ordering: [sequentially consistent](https://marabos.nl/atomics/memory-ordering.html#seqcst).
Vectornaut added 1 commit 2024-11-19 00:14:22 +00:00
For future thread-safety, keep the next serial number in a static atomic
variable.
Author
Collaborator

I think the app prototype should be single-threaded for now, so for parsimony we could instead store the next serial number in a thread-local cell, as suggested in this other StackOverflow answer. The thread-local version is ready to go, so let me know which version you'd prefer to review.

I think the app prototype should be single-threaded for now, so for parsimony we could instead store the next serial number in a thread-local cell, as suggested in [this other StackOverflow answer](https://stackoverflow.com/a/32936064). The thread-local version is ready to go, so let me know which version you'd prefer to review.
Vectornaut added 1 commit 2024-11-19 04:30:10 +00:00
In the last revision, the next element serial number was thread-safe,
but that might be overdoing it. I suspect that elements will only ever
be created from the main thread.
Author
Collaborator

As discussed over e-mail, we'll go with the thread-local version for now. Ready to review!

As discussed over e-mail, we'll go with the thread-local version for now. Ready to review!
Vectornaut added 3 commits 2024-11-22 00:42:56 +00:00
This reverts commit 7bc3a9eeae.

I'd hoped that `thread_local!` would force our code to be single-
threaded, but apparently it doesn't. With a global mutable static, it
seems like we have to include some kind of thread-safety to avoid
`unsafe` code, and an atomic provides the kind of safety we actually
want.
Vectornaut added 1 commit 2024-11-22 00:47:55 +00:00
Commit 133b725 should make it impossible for the serial numbers to wrap.
Author
Collaborator

As discussed in our meeting, I've gone back to the atomic version, with one change: we now panic when we run out of serial numbers, rather than silently wrapping around. Ready to review again!

As discussed in our meeting, I've gone back to the atomic version, with one change: we now panic when we run out of serial numbers, rather than silently wrapping around. Ready to review again!
Owner

Looks good; code is pretty straightforward, and it runs fine, and switching assemblies is smooth. Merging.

Looks good; code is pretty straightforward, and it runs fine, and switching assemblies is smooth. Merging.
glen merged commit e917272c60 into main 2024-11-22 02:25:11 +00:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: glen/dyna3#22
No description provided.