Skip to content
This repository was archived by the owner on Aug 27, 2023. It is now read-only.

Not thread safe #3

Open
RuiAAPeres opened this issue May 3, 2016 · 0 comments
Open

Not thread safe #3

RuiAAPeres opened this issue May 3, 2016 · 0 comments

Comments

@RuiAAPeres
Copy link

RuiAAPeres commented May 3, 2016

I was looking at the implementation and I didn't see any locking mechanism for inserting/removing the elements. So I did quick test:

    func testThreadSafety() {
        var a: ObservableArray<String> = ["foo"]

        _ = expectationWithDescription("")
        a.rx_events().subscribeNext { _ in }
            .addDisposableTo(disposeBag)

        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
            for _ in 0 ..< Int.max {
                a.append("buzz")
            }
        }

        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)) {
            for _ in 0 ..< Int.max where a.isEmpty != true {
                if a.isEmpty == false  {
                    a.removeFirst()
                }
            }
        }

        waitForExpectationsWithTimeout(1) { (error) in
            XCTAssertNil(error, "\(error)")
        }
    }

This will make the lib crash.

ghost pushed a commit to mojio/ObservableArray-RxSwift that referenced this issue May 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant