Skip to main content

While trying to figure out how to implement a Producer/Consumer Queue in Qt, I stumpled upon several SO answers, blogs and sites linking to this site:

You're doing it wrong...You're doing it wrong...

I got the point of this site, but people are usually referring to the code example which is in the referenced blog:

Threading without the headacheThreading without the headache

The blog has a small code example attached, the core of it being posted by KornP in this SO answer:

Qt moveToThread() vs calling new thread when do we use each

So if you take a closer look we have the following behaviour:

  1. Producer P produces an item, while Consumer C waits for events to appear in its event loop.
  2. P forwards the produced data through a signal and returns to event loop idling.
  3. C receives the signal in its event loop and consumes the data.
  4. C emits a signal to the producer thread and returns to event loop idling.
  5. Start over from 1.

In other words: while P is producing, C does nothing and while C is producing, P does nothing.

What is the point of having a producer and consumer like this in two different threads?
Wouldn't a single thread accomplish exactly the same?

While trying to figure out how to implement a Producer/Consumer Queue in Qt, I stumpled upon several SO answers, blogs and sites linking to this site:

You're doing it wrong...

I got the point of this site, but people are usually referring to the code example which is in the referenced blog:

Threading without the headache

The blog has a small code example attached, the core of it being posted by KornP in this SO answer:

Qt moveToThread() vs calling new thread when do we use each

So if you take a closer look we have the following behaviour:

  1. Producer P produces an item, while Consumer C waits for events to appear in its event loop.
  2. P forwards the produced data through a signal and returns to event loop idling.
  3. C receives the signal in its event loop and consumes the data.
  4. C emits a signal to the producer thread and returns to event loop idling.
  5. Start over from 1.

In other words: while P is producing, C does nothing and while C is producing, P does nothing.

What is the point of having a producer and consumer like this in two different threads?
Wouldn't a single thread accomplish exactly the same?

While trying to figure out how to implement a Producer/Consumer Queue in Qt, I stumpled upon several SO answers, blogs and sites linking to this site:

You're doing it wrong...

I got the point of this site, but people are usually referring to the code example which is in the referenced blog:

Threading without the headache

The blog has a small code example attached, the core of it being posted by KornP in this SO answer:

Qt moveToThread() vs calling new thread when do we use each

So if you take a closer look we have the following behaviour:

  1. Producer P produces an item, while Consumer C waits for events to appear in its event loop.
  2. P forwards the produced data through a signal and returns to event loop idling.
  3. C receives the signal in its event loop and consumes the data.
  4. C emits a signal to the producer thread and returns to event loop idling.
  5. Start over from 1.

In other words: while P is producing, C does nothing and while C is producing, P does nothing.

What is the point of having a producer and consumer like this in two different threads?
Wouldn't a single thread accomplish exactly the same?

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

While trying to figure out how to implement a Producer/Consumer Queue in Qt, I stumpled upon several SO answers, blogs and sites linking to this site:

You're doing it wrong...

I got the point of this site, but people are usually referring to the code example which is in the referenced blog:

Threading without the headache

The blog has a small code example attached, the core of it being posted by KornP in this SO answer:

Qt moveToThread() vs calling new thread when do we use eachQt moveToThread() vs calling new thread when do we use each

So if you take a closer look we have the following behaviour:

  1. Producer P produces an item, while Consumer C waits for events to appear in its event loop.
  2. P forwards the produced data through a signal and returns to event loop idling.
  3. C receives the signal in its event loop and consumes the data.
  4. C emits a signal to the producer thread and returns to event loop idling.
  5. Start over from 1.

In other words: while P is producing, C does nothing and while C is producing, P does nothing.

What is the point of having a producer and consumer like this in two different threads?
Wouldn't a single thread accomplish exactly the same?

While trying to figure out how to implement a Producer/Consumer Queue in Qt, I stumpled upon several SO answers, blogs and sites linking to this site:

You're doing it wrong...

I got the point of this site, but people are usually referring to the code example which is in the referenced blog:

Threading without the headache

The blog has a small code example attached, the core of it being posted by KornP in this SO answer:

Qt moveToThread() vs calling new thread when do we use each

So if you take a closer look we have the following behaviour:

  1. Producer P produces an item, while Consumer C waits for events to appear in its event loop.
  2. P forwards the produced data through a signal and returns to event loop idling.
  3. C receives the signal in its event loop and consumes the data.
  4. C emits a signal to the producer thread and returns to event loop idling.
  5. Start over from 1.

In other words: while P is producing, C does nothing and while C is producing, P does nothing.

What is the point of having a producer and consumer like this in two different threads?
Wouldn't a single thread accomplish exactly the same?

While trying to figure out how to implement a Producer/Consumer Queue in Qt, I stumpled upon several SO answers, blogs and sites linking to this site:

You're doing it wrong...

I got the point of this site, but people are usually referring to the code example which is in the referenced blog:

Threading without the headache

The blog has a small code example attached, the core of it being posted by KornP in this SO answer:

Qt moveToThread() vs calling new thread when do we use each

So if you take a closer look we have the following behaviour:

  1. Producer P produces an item, while Consumer C waits for events to appear in its event loop.
  2. P forwards the produced data through a signal and returns to event loop idling.
  3. C receives the signal in its event loop and consumes the data.
  4. C emits a signal to the producer thread and returns to event loop idling.
  5. Start over from 1.

In other words: while P is producing, C does nothing and while C is producing, P does nothing.

What is the point of having a producer and consumer like this in two different threads?
Wouldn't a single thread accomplish exactly the same?

Source Link
Tim Meyer
  • 863
  • 1
  • 8
  • 14

Common Qt Producer/Consumer Example: What is the point of multithreading here?

While trying to figure out how to implement a Producer/Consumer Queue in Qt, I stumpled upon several SO answers, blogs and sites linking to this site:

You're doing it wrong...

I got the point of this site, but people are usually referring to the code example which is in the referenced blog:

Threading without the headache

The blog has a small code example attached, the core of it being posted by KornP in this SO answer:

Qt moveToThread() vs calling new thread when do we use each

So if you take a closer look we have the following behaviour:

  1. Producer P produces an item, while Consumer C waits for events to appear in its event loop.
  2. P forwards the produced data through a signal and returns to event loop idling.
  3. C receives the signal in its event loop and consumes the data.
  4. C emits a signal to the producer thread and returns to event loop idling.
  5. Start over from 1.

In other words: while P is producing, C does nothing and while C is producing, P does nothing.

What is the point of having a producer and consumer like this in two different threads?
Wouldn't a single thread accomplish exactly the same?