-
Notifications
You must be signed in to change notification settings - Fork 934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
internal/task: use a lock-free queue #2290
base: dev
Are you sure you want to change the base?
Conversation
Oops, i meant FIFO not LIFO. Also xtensa seems to still need work? |
Size impact statistics:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity: do you have plans to use the changes in this PR? Any new features this will add?
I haven't looked too deeply into the queue code but I don't see anything surprising with a quick glance.
src/runtime/arch_avr.go
Outdated
@@ -14,3 +17,14 @@ func align(ptr uintptr) uintptr { | |||
} | |||
|
|||
func getCurrentStackPointer() uintptr | |||
|
|||
//export __sync_val_compare_and_swap_2 | |||
func __sync_val_compare_and_swap_2(ptr *uint32, expected, desired uint32) uint32 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same goes for AVR.
Note that atomics are somewhat broken on AVR. If you see weird behavior on AVR, it could be the backend that is emitting invalid instructions.
For more details, see: https://reviews.llvm.org/D97127
I am not intending to do anything specific right now, but this might be useful once we want to implement multicore support for something.
Right now:
The Push operation can also be safely called concurrently. . . but only if the tasks are pinned safely (which is currently an issue, but this is more of a future thing). |
6b7d551
to
27813be
Compare
This has been rebased now that #2307 is merged |
I still need to test this fully on AVR though |
This changes task.Stack and task.Queue to use atomic compare-and-swap operations. With this change, they can also be executed safely from multiple threads/cores. Additionally, the queue is actually LIFO now (not sure what I was thinking before).
Seems like this is perhaps not working correctly on the HiFive1b? I tried several times, and also ran some other test code successfully. |
@aykevl If this is correct, would you be willing to merge it? |
I think we can close this now? |
This changes task.Stack and task.Queue to use atomic compare-and-swap operations.
With this change, Push can also be executed safely from multiple threads/cores.
Additionally, the queue is actually LIFO now (not sure what I was thinking before).
Not entirely sure about this yet.