Possible Duplicate:
GCD : How to write and read to variable from two threads
I am developing a iOS app in which i am using sqlite database.I have to perform multithreading but on sqlite database I am able to do only one thing at a time.So I need to implement concept of semaphore .So plz help me
You can use the
@synchronizeddirective as a mutex. If you have all your methods for manipulating the sqlite database in a single data manager created using a singleton and shared throughout the project you can use that object as the lock token, e.g.:And from within the data manager you can use
@synchronized(self)for the same protection.You will only need a mutex for this so don’t worry about extra code for implementing semaphores.