ChannelsCPP icon indicating copy to clipboard operation
ChannelsCPP copied to clipboard

Unable to read remaining values after channel is closed

Open codeReaper2001 opened this issue 2 years ago • 0 comments

int main() {
    Chan<int> intChan;
    thread t1 = thread([&]() {
        for (int i = 0; i < 10; ++i) {
            intChan << i;
        }
        Close(intChan);
    });

    thread t2 = thread([&]() {
        for(int &x : intChan) {
            cout << x << endl;
        }
    });
    t1.join();
    t2.join();
}

the output is: image Is this a bug or is my usage incorrect?

codeReaper2001 avatar Jan 01 '23 07:01 codeReaper2001