     }
 
     func sortPlaces(byLocation location: CLLocation) {
-        self.placesLock.lock()
-        let sortedPlaces = PlaceUtilities.sort(places: places, byDistanceFromLocation: location)
-        self.places = sortedPlaces
-        self.placesLock.unlock()
+        self.placesLock.withWriteLock {
+            let sortedPlaces = PlaceUtilities.sort(places: places, byDistanceFromLocation: location)
+            self.places = sortedPlaces
+        }
     }
 }

        let places = database.getPlaceKeys(aroundPoint: location, withRadius: radius).andThen(upon: queue) { (placeKeyToLoc) -> Future<[DatabaseResult<Place>]> in
            var unfetchedPlaces = [String]()
            var fetchedPlaces = [Deferred<DatabaseResult<Place>>]()
            self.placesLock.lock()
            for placeKey in Array(placeKeyToLoc.keys) {
                if let index = (self.places.index { (place) -> Bool in
                    place.id == placeKey
                }) {
                    let place = self.places[index]
                    fetchedPlaces.append(Deferred(filledWith: DatabaseResult.succeed(value: place)))
                } else {
                    unfetchedPlaces.append(placeKey)
                }
            }
            self.placesLock.unlock()
            // TODO: limit the number of place details we look up. X closest places?
            // TODO: These should be ordered by display order
            return (self.database.getPlaceDetails(fromKeys: unfetchedPlaces) + fetchedPlaces).allFilled()
        }
        return places

    private func displayPlaces(places: [Place], forLocation location: CLLocation) {
        let filteredPlaces = PlaceUtilities.filterPlacesForCarousel(places)
        return PlaceUtilities.sort(places: filteredPlaces, byTravelTimeFromLocation: location, ascending: true, completion: { sortedPlaces in
            self.placesLock.withWriteLock {
                self.places = sortedPlaces
            }
            DispatchQueue.main.async {
                self.placesLock.withReadLock {
                    self.delegate?.placesProvider(self, didReceivePlaces: self.places)
                }
                if self.firstFetch {
                    self.delegate?.placesProviderDidFetchFirstPlace()
                    self.firstFetch = false
