Hi All,

I have a doubt regarding "threadsafe". Consider the following scenario....

Thread #1:
          fun1() {
                  lock();
                  writestring(ptr, pconfig);
                  unlock();
                  }

     Thread #1:
          fun2() {
                   lock();
                   writestring(ptr, pconfig);
                   unlock();
                   }

          bool writestring(char *ptr, char *pconfig) {
              //this code should not be shared across threads. One thread should access at                                          
              //given point of time 
              memcpy();
              ............
              }

My doubt here is :

Will writestring is accessed by only one thread at any given point of time i.e. Is it Thread Safe? If no, then how can I make it threadsafe?

My application is multithreaded and crashing at memcpy i.e. memory corruption. Is thread safe is the reason for memory corruption? Please reply me.

Thanks in advance.

put the locks in writestring().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.