Step Into Labs

Step Into C · Module exam · Win32 in Depth

Exam: Four Threads, One File

Read a file with handles, split the work across threads and add it up without a race.

Part of Step Into C. The full module exam, its missions and the real compiler and debugger are in the course. Try a free lesson first to see how it works.

Counting lines is easy. Counting them with four threads at once, straight from a buffer you allocated from the operating system, without a single lost update, is the kind of thing Windows services do all day. Build the counter: open the file with a handle, pull it into memory in one read, hand a quarter to each thread, wait for all of them, and add up what they found.

In this module exam

Missions

  1. Count in parallel