tag:bettong.net,:/tag/scheduling Urban Hafner : Tag scheduling, everything about scheduling 2007-05-08T08:01:12+00:00 Typo tag:bettong.net,:Article/65 2005-11-06T16:39:50+00:00 2007-05-08T08:01:12+00:00 Urban Hafner CTM: Exercise 4-6

The problem

Thread scheduling. Section 4.8.3.2 shows how to skip over already-calculated elements of a stream. If we use this technique to sum the elements of the integer stream in section 4.3.1, the result is much smaller than 11249925000, which is the sum of the integers in the stream. Why is it so much smaller? Explain this result in terms of thread scheduling.

My solution

What probably happens is that generating another element in the production thread is so fast that more than one ca be generated in one time slice. When the consumer thread restarts in the next slice it only takes the last element computed, so it loses some (or many) elements.

The problem

Thread scheduling. Section 4.8.3.2 shows how to skip over already-calculated elements of a stream. If we use this technique to sum the elements of the integer stream in section 4.3.1, the result is much smaller than 11249925000, which is the sum of the integers in the stream. Why is it so much smaller? Explain this result in terms of thread scheduling.

My solution

What probably happens is that generating another element in the production thread is so fast that more than one ca be generated in one time slice. When the consumer thread restarts in the next slice it only takes the last element computed, so it loses some (or many) elements.