I want to run two functions one after the other that accesses a third function with a condition that when the first is using the third, the second function should wait. It should be able to use the third function after first time period of accessing the third function over.
This concept sounds like implementing round robin scheduling with context switching. I know this theoretically, but I want to apply it practically. How can I achieve this and do context switching? Can someone provide me an example to do this? Is there any other way to achieve this as well?
EDIT: Actually i am plotting markers on google maps ,using gmap.net .i have created two thread functions for the two markers.they will be fetching the required data from two separate files.converting it into lat long and plotting on map.with this approach i am creating duplicate functions for both having same functionality.but i guess its not a good way of programming so want to use one common function for plotting and fetching data from file to convert .
so when one thread is accessing the common function another one should wait .once first one release the function or its time period to work on that function is exceeded it should perform context switch and second thread should access the common function.
this is what i am trying to achieve.if i should modify my approach please do let me know.