FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [July 2017 Threads] Global Vairable handing in FreeRTOSPosted by gauravpatni on July 21, 2017 Dear All,
We have just started development based on Free RTOS .But we are unable to find 'recommended' way of handling global variable . Please refer following case :
External int is use for counting digital sensor values .
multiple task need to get this digital sensor count for further processing ( read only ) .
As may times i read that use of global vairable is crude method in multitasking system . So request you to please help me by suggesting suitable / recommended method .
Regards,
Gaurav
Global Vairable handing in FreeRTOSPosted by rtel on July 21, 2017 If you have one writer and multiple readers, and the update to the variable is atomic (i.e. the variable is updated in one write, like a 32-bit value being updated in a single 32-bit write as opposed to two 16-bit writes) then an external variable is a very efficient way of doing what you want. You could get issues with multiple writer scenarios though.
Global Vairable handing in FreeRTOSPosted by gauravpatni on July 21, 2017 Thanks for quick reply .
"external variable" means Global variable ?
also please let me know the recommended way for implementing "multiple writer " & " multiple reader " . This will be helpful for future application development .
Regards,
Gaurav
Global Vairable handing in FreeRTOSPosted by richard_damon on July 21, 2017 Gaurav,
When you get into Multiple Writers, Multiple Readers, the big question comes to what do you mean by this and what are behavior are you expecting. At the simple level, it still will just work with a simple atomic int. The variable will have the value last written when every reader reads it. That means if one task writes a value of 5, then another task writes the value 10, after that point all readers will see the 10, and a reader which reads between the two writes will see a 5. If there is no interactions between the writers to synchronize the writes, then it is possible that under other conditions, the 10 might have occurred first, and then the final value would be the 5, so you have some uncertainty due to the 'race' condition. Similarly for the readers, if there is nothing synchronizing them to the writers, eventually they will see the later value, but if they happen to read before the last write, they will see the earlier write. Another 'race' condition.
Normally, this sort of variability isn't desired, but there are conditions where it might be acceptable. Thus definition is needed.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|