AW: [En-Nut-Discussion] global variable

Vesa Jääskeläinen chaac at nic.fi
Sat Aug 12 12:08:41 CEST 2006


Hi,

You might want to declare your variable as volatile so compiler won't
optimize some cases out.

In example:
volatile int global_var;

Thanks,
Vesa Jääskeläinen

Ernst Stippl wrote:
> Hi!
> 
> I am not sure if I understood your question, but here is what I can offer:
> 
> Have a look at the Ethernut Sample program "threads.c":
> 
> Insert a variable definition between the "include" and the thread
> definition:
> 
> #include <sys/thread.h>
> #include <sys/timer.h>
> 
> int global_var;            // <-- insert here
> 
> /*
>  * High priority thread.
>  */ 
> 
> As far as I can see, the variable global_var will be accessible by both
> threads, they can read/write it. But you have to invent a set of rules to
> make sure access to the variable to done in an orderly fashion. Otherwise
> both threads MAY write to the variable and so changes to it could get lost.
> 
> regard
> ernst 
> 
> 
> -----Ursprüngliche Nachricht-----
> Von: en-nut-discussion-bounces at egnite.de
> [mailto:en-nut-discussion-bounces at egnite.de] Im Auftrag von Raul Valle
> Gesendet: Samstag, 12. August 2006 03:45
> An: en-nut-discussion at egnite.de
> Betreff: [En-Nut-Discussion] global variable
> 
> hi all , how can i use one variable that is able to work for all threads,
> that if i modify its value one one thread , in the other can reflect that
> change _______________________________________________
> En-Nut-Discussion mailing list
> En-Nut-Discussion at egnite.de
> http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion
> 
> 
> 
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.405 / Virus Database: 268.10.9/417 - Release Date: 11.08.2006
> 
> 
> 




More information about the En-Nut-Discussion mailing list