Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

getRecord() method hangs on simultaneous request. #137

Open
zebpaynikunj opened this issue Feb 18, 2019 · 0 comments
Open

getRecord() method hangs on simultaneous request. #137

zebpaynikunj opened this issue Feb 18, 2019 · 0 comments

Comments

@zebpaynikunj
Copy link

zebpaynikunj commented Feb 18, 2019

` @ObjectiveCName("getRecord:")
public Record getRecord( String name ) {
Record record = null;

    recordsLock.lock();
    try {
        record = records.get( name );
        if( record == null ) {
            record = createRecord(name);
            recordsLock.unlock();
            record.start();
        } else if (record.getAndIncrementUsage() <= 0) {
            // Some other thread is discarding this record. We need the record out of the records
            // map before we can put the new record there so we will finish the discard here. Either this
            // thread or the other thread will end up finishing the discard.
            record.finishDiscard();

            assert records.get(name) == null;
            record = createRecord(name);
            recordsLock.unlock();
            record.start();
        }
    } finally {
        if (recordsLock.isHeldByCurrentThread()) {
            recordsLock.unlock();
        }
    }

    if (!record.isReady()) {
        final CountDownLatch readyLatch = new CountDownLatch(1);
        record.whenReady(new Record.RecordReadyListener() {
            @Override
            public void onRecordReady(String recordName, Record record) {
                readyLatch.countDown();
            }
        });
        try {
            readyLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    return record;
}`

this method does not return record object when more than one thread tried to access it.

@zebpaynikunj zebpaynikunj changed the title getRecord() method does not record when simultaneoulsy request made for record getRecord() method does not record when simultaneously request made for record Feb 18, 2019
@zebpaynikunj zebpaynikunj changed the title getRecord() method does not record when simultaneously request made for record getRecord() method hangs on simultaneous request. Feb 18, 2019
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