On 2008-09-11 16:11, (e-mail address removed) wrote:
How to make flowing Code to behave as Re-Entrant ( concurrently
accessed safely by Multiple user )
Func( )
{
.
static char buffer_1 [1024] ;
/* few write Operation on buffer */
.
.
static char buffer_2 [1024] ;
/* few write Operation on buffer */
.
.
.
static char buffer_3 [1024] ;
/* few write Operation on buffer */
.
.
}- Hide quoted text -
Can you use the Boost libraries in your codebase? If so, check out the
synchronisation mechanisms in Boost.Interprocess (
http://www.boost.org/
doc/libs/1_36_0/doc/html/interprocess/
synchronization_mechanisms.html).
Alternatively, are you on Win32? Take a look at the WINAPI call
EnterCriticalSection().
A reentrant function is not just thread-safe, it can also safely call
iteself, which usually is not possible if the function has any static
variables.
I don´t really understand why a function with static variables usually
cannot call itself?? What I think that would happen is that that
identifier refers to the same memory position in both the caller an
the calee, right? But, where´s the problem?
--
Erik Wikström
Consider a senario
we have Above code in Shared Library
user_1 has updated buffer 1 & 2 ...... He require data of either
buffer to compute for buffer 3
But i mean time user_2 start executing the function and changes data
stored in buffer 1
User_2 Corrupts Data of User_1 Un-knowingly