Synchronizing the access of concurrent threads to shared memory, in order to prevent unwanted interference is a basic problem in multithreaded programming. Thread synchronization mechanism provides a means of restricting the possible inter-leavings of threads, thereby reducing non-determinacy and allowing stronger program properties to be maintained. For example locks are often used around update operations on shared data to ensure mutual exclusion. Concurrency should be a language feature and a part of language specifications. The core idea of this paper is that the compiler is made to identify the critical section in a multithreaded program for the synchronization, which currently is not a C language feature in gcc (GNU Compiler Collection) compiler. The idea behind this technique is that compiler will automatically take care of the critical section by introducing Lock and Unlock function calls in a multithreaded program without involvement of the programmers. (A critical section of a multithreaded program is a section of code where shared data are accessed by the multiple threads).