Skip to content

Example for a global variable in a shared library.#183

Open
funny0facer wants to merge 7 commits intozesterer:masterfrom
funny0facer:example_for_global_variable
Open

Example for a global variable in a shared library.#183
funny0facer wants to merge 7 commits intozesterer:masterfrom
funny0facer:example_for_global_variable

Conversation

@funny0facer
Copy link
Contributor

Referring to #90, I hope this example is considered useful.

Copy link
Owner

@zesterer zesterer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm not entirely convinced that this is a worthwhile example. spin is specifically not intended for guarding state in a multi-threaded hosted environment: std::sync should be used instead due to concerns like priority inversion. While it's sound to do so, it's almost never a good idea.

use library::*;

fn main() {
// Imagine having separate idependant processes connecting to the same shared library to get access to hardware ressources.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some typos and grammatical issues here, and in other comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair point, maybe I tried to oversimplify the example.
I built https://github.com/funny0facer/esp32_interrupts1 and there I use your Mutex to lock a global variable.

@funny0facer
Copy link
Contributor Author

Maybe you like the new version better.. I focused it now on the use case mentioned on https://doc.rust-lang.org/edition-guide/rust-2024/static-mut-references.html

@funny0facer
Copy link
Contributor Author

I added also an example for spin::Once.
Please let me know if this kind of example is even the thing you were looking for or if you expect something different.

@funny0facer funny0facer force-pushed the example_for_global_variable branch from 4832908 to ed79ebd Compare February 5, 2026 19:50
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.

2 participants