Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

To lock() or not to lock()



Hi All,

I have an EOF question regarding locking. The documentation on the EOEditingContext lock() method says the following:

---
Locks access to this EOEditingContext to prevent other threads from accessing it. If it has a shared editing context, this EOEditingContext takes a reader lock on it as well. You should lock an editing context when you are accessing or modifying objects managed by the editing context. The thread safety provided by Enterprise Objects Framework allows you to have one thread to be active in each EOEditingContext and one thread to be active in each EODatabaseContext (EOAccess). In other words, multiple threads can access and modify objects concurrently in different editing contexts, but only one thread can access the database at a time (to save, fetch, or fault).
---


My interpretation of this is that I can have thread1 working in one editing context and thread2 working in a second editing context. These two editing contexts by default share the eoaccess level objects to access the database. So when either thread calls the EOEditingContext saveChanges() or objectsWithFetchSpecification() to fetch objects then EOF obtains a lock to prevent the other thread from accessing the eoaccess layer and doing a save/fetch at the same time.

So it would seem to me that thread1 and thread2 do not need to worry about locking their editing context when they are using them. I would have to worry about locking an editing context only if I were to have separate threads working on the same editing context. Are these assumptions valid? Or should I lock the editing contexts?

Thanks for any advise.

Ricardo Parada
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/email@hidden


This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.