Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question: channels and slow processes #188

Closed
utkarshayachit opened this issue Oct 15, 2018 · 7 comments
Closed

question: channels and slow processes #188

utkarshayachit opened this issue Oct 15, 2018 · 7 comments
Assignees
Milestone

Comments

@utkarshayachit
Copy link

utkarshayachit commented Oct 15, 2018

This is more of a question than and issue. Please feel free to point to some other mechanism for asking similar questions.

Here's my code snippet

int main(int, char* [])
{
  auto c = stlab::channel<int>(stlab::default_executor);
  auto& sender = c.first;
  auto& receiver = c.second;

  auto hold = receiver |
    /** STEP 1 **/
    [](const int& val) { std::cout << "step 1: {" << val << "}" << std::endl; return val; } |

    /** STEP 2 **/
    [](int val) {
      std::cout << " step 2: start {" << val << "}" << std::endl;
      using namespace std::chrono_literals;
      std::this_thread::sleep_for(1s);
      std::cout << " step 2: end {" << val << "}" << std::endl;
    };
  receiver.set_ready();

  std::cout << "start sending" << std::endl;
  for (int cc=0; cc < 5; cc++)
  {
    sender(cc);
  }
  std::cout << "done sending" << std::endl;

  using namespace std::chrono_literals;
  std::this_thread::sleep_for(10s);
  std::cout << "done" << std::endl;
  return EXIT_SUCCESS;
}

The output generated is

start sending
done sending
step 1: {0}
 step 2: start {0}
step 1: {1}
 step 2: end {0}
 step 2: start {1}
step 1: {2}
 step 2: end {1}
 step 2: start {2}
step 1: {3}
 step 2: end {2}
 step 2: start {3}
step 1: {4}
 step 2: end {3}
 step 2: start {4}
 step 2: end {4}
done

What I have here is two function-processes; the second one is slow, while the first one is fast. What I see is that as the second one waits, the first step is no longer invoked after it has produced one value. Since default incoming queue size for each process is unlimited ref, I was expecting that the the step-1 will process all the packets and enqueue the result to be processed by step 2 whenever it gets to it. What am I misinterpreting?

Thanks

@FelixPetriconi
Copy link
Member

A similar question was raised before, I think. See Sean's explanation: #165 (comment)

@utkarshayachit
Copy link
Author

looking at the explanation, I am even more confused. @sean-parent says "A processes will be allowed to run so long as it is yielding values until the buffer is full before it is suspended.". In that case, why the process for step-1 suspended at all? It is yielding values as far as I can tell and the buffer should not be full.

@sean-parent
Copy link
Member

sean-parent commented Oct 15, 2018 via email

@utkarshayachit
Copy link
Author

utkarshayachit commented Oct 16, 2018

great! thanks for checking. Yes, I had tried adding the stlab::buffer_size{..} to both step 1 and then step 2 to no avail.

@FelixPetriconi
Copy link
Member

I just went through it with the debugger and I think, I know where it goes wrong. I will try to provide a fix until the end of the week.

@utkarshayachit
Copy link
Author

thanks guys. I've posted an MR to fix the doc for buffer_size as well (stlab/stlab.github.io#52).

FelixPetriconi added a commit to FelixPetriconi/libraries that referenced this issue Oct 17, 2018
@FelixPetriconi FelixPetriconi added this to the 1.4 milestone Nov 29, 2018
@FelixPetriconi FelixPetriconi self-assigned this Nov 29, 2018
FelixPetriconi added a commit that referenced this issue Nov 30, 2018
Extend channel void / fix buffer_size of channels / receiver<std::reference_wrapper<>>
This fixed #206, #188
@FelixPetriconi
Copy link
Member

Done in 1.4

nickpdemarco pushed a commit that referenced this issue Aug 4, 2022
default buffer size of an incoming queue is 1, not unlimited (see #188)

Co-authored-by: Foster Brereton <fbrereto@adobe.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants