I need to have data synchronization in my code. Currently I am accessing a global value inside interrupt and also in a local function which may corrupt the data if interrup
Interrupts work differently than threads or processes - if a thread waits for a semaphore, it is simply not scheduled until either the semaphore gets available or, if given, the wait timeout elapses. In the mean while, other threads can be scheduled, one of those potentially giving back the semaphore.
This is not the case with interrupt service routines - these won't be interrupted by any thread scheduling (if at all, then only by other interrupts), but are executed until they return. So if a ISR gets to wait for a semaphore (or a similar mechanism, as you asked for), we are in a deadlock as the thread holding it can't be scheduled any more either to give the semaphore back...
So you need a totally different mechanism!
The usual way to do this is to disable the interrupt as long as your function needs to access the common data, and re-enable it afterwards (and you potentially need to do this within the ISR itself, too).
How? Well, OS/hardware specific - as long as you do not provide further details, I'm out here...
Just some hints yet: Keep the period of disabled interrupts as short as possible and make sure that the commonly accessed data is declared volatile!