Skip to content
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

Suggest using volatile attribute on ptYielded #3

Open
Xeenych opened this issue Jan 9, 2020 · 4 comments
Open

Suggest using volatile attribute on ptYielded #3

Xeenych opened this issue Jan 9, 2020 · 4 comments

Comments

@Xeenych
Copy link

Xeenych commented Jan 9, 2020

If protothread does not have any PT_YIELD() in its Run method then compiler produces a warning, that ptYielded is set but never used.

I suggest using volatile attribute on ptYilded so compiler won't optimize (void) ptYielded; statement and won't produce any warnings.

#define PT_BEGIN() bool volatile ptYielded = true; (void) ptYielded; switch (_ptLine) { case 0:

For example I have this code without any PT_YILED()


		PT_BEGIN();
		PT_SPAWN(task1);
		PT_SPAWN(task2);
		
		readtask.Run();
		task3.Run();
		PT_WAIT_THREAD(readtask);
		PT_WAIT_THREAD(task3);
		//PT_YIELD();
		PT_END();
@benhoyt
Copy link
Owner

benhoyt commented Sep 25, 2021

Sorry for not responding to this earlier! I'm curious (and I haven't written a lot of C for a while): why doesn't the (void) ptYielded cause the compiler to not produce a warning here?

@marek22k
Copy link

marek22k commented Sep 8, 2023

Alternatively, you could use __attribute__((unused)).

@marek22k
Copy link

marek22k commented Sep 8, 2023

why doesn't the (void) ptYielded cause the compiler to not produce a warning here?

This will cast it to the type void. The compiler then seems to think that the value is used because it was casted.

@cmorty
Copy link
Contributor

cmorty commented Dec 28, 2024

volatile is a very bad idea and was deprecated in current C++ - standards, except for hardware-registers, for good reasons (mainly because a lot of people did not understand the implications on multi-core systems).
@Xeenych : I wonder which compiler ignores the void-cast and gives you a warning about unused ptYielded.
@marek22k : __attribute__((unused)) is a gcc extension (and [maybe_unused] is C++23 ;-) )

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

No branches or pull requests

4 participants