Give each element a serial number #22

Open
Vectornaut wants to merge 2 commits from element-serial into main
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!
This pull request can be merged automatically.
You are not authorized to merge this pull request.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin element-serial:element-serial
git checkout element-serial
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
1 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.