Rust. Best way to share state for many threads #773
Replies: 6 comments 5 replies
-
The model itself is not thread safe and cannot be sent to another thread. (Edit: link fixed) |
Beta Was this translation helpful? Give feedback.
-
Disclaimer: I am also new to rust.
Because we got elements in our ListItemData per compile time i needed to be a bit creative or hacky... I simpy added a visible boolean value to ListITemData that gets manipulated in the thread. If you want an List item you just get one of the array and set the visible value to true . |
Beta Was this translation helpful? Give feedback.
-
i must have been wrong with the fixed size of the arrays. i checked the memory example again and there is an good example how to increase the size of an array in the .60 file . in the case of the memory example initialy the array is only 8 elemnts big, its gets cloned and doubled in the end. look through this i think it will help. |
Beta Was this translation helpful? Give feedback.
-
@ogoffart , @tronical , @Vollbrecht , Hi all. I've accumulated some experience and I'd like to give you feedback on interfaces... @ogoffart, Needed to read your answers more attentively though. Thank you for guidance! P.S. Happy New Year! |
Beta Was this translation helpful? Give feedback.
-
@ogoffart , @tronical , @Vollbrecht What can I tall about my experience with Rust? Main thing which was hard for me was passing data around. Ideas that I have...
Extra thing what confused me was that VecModel has semantics of "mutable reference". That's probably it. Quite an essay I wrote. I hope this will be some use for you. |
Beta Was this translation helpful? Give feedback.
-
What is working as well is to define a callback in your .60 file and request the invocation of that callback from another thread. It's not quite what callbacks are designed for in sixtyfps (I think), but it might simplify the handling of shared states.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm trying to reimplement my C++ example for async counter with some jobs imitation and latency in Rust.
(C++: https://github.com/DaMilyutin/sixtyfps-cpp-template-worker-threads)
And I got into some difficulties here.
First to know, I'm new to Rust. I've read and watched some stuff but never practiced.
So I'm probably may ask some noob questions here.
What I have found now is that I must attach Rc wrapped VecModel to ui
But I can not change it in other spawned threads. I get error messages like
" sixtyfps::invoke_from_event_loop(|| {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Rc<VecModel<ListItemData>>
cannot be shared between threads safely"
I'm not sure what I'm doing wrong. There are so many strange to me wrappers in Rust:
Rc, Arc, ... etc 😄
When I change
Rc
toArc
I get type mismatch for argument forui.set_task_data_model
. I'm so confused.Since I'm trying to make something similar to my C++ code, I probably think in wrong paradigm.
Please, advise any tools, paradigms or approaches to acomplish this async example,
See my code and error messages in zip:
counter-with-jobs.zip
Thank you for any help.
And Merry X-mas.
(We have orthodox X-mas in Jan7)
Beta Was this translation helpful? Give feedback.
All reactions