A Tech Log

January 27, 2009

Ordered Execution With ThreadPool

Filed under: Development — adallow @ 9:38 pm
Tags: ,

Interesting from:


“Consider a pipeline implementation that obtains parallelism benefits by having multiple stages of the pipeline active at any one time.

For example, you could have a pipeline that reads in data from a file, compresses it, encrypts it, and writes it out to a new file. The compression can be done concurrently with the encryption, but not on the same data at the same time, since the output of one needs to be the input to the other. Rather, the compression routine can compress some data and send it off to the encryption routine to be processed, at which point the compression routine can work on the next piece of data.
Since many compression and encryption algorithms maintain a state that affects how future data is compressed and encrypted, it’s important that ordering is maintained. (Never mind that this example deals with files, and it’d be nice if you could decrypt and decompress the results in order to get back the original with all of the data in the correct order.)
There are several potential solutions. The first solution is simply to dedicate a thread to each component. This DedicatedThread would have a first-in-first-out (FIFO) queue of work items to be executed and a single thread that services that queue. When the component has work to be run, it dumps that work into the queue, and eventually the thread will get around to picking up the work and executing it. Since there’s only one thread, only one item will be run at a time. And as a FIFO queue is being used, the work items will be processed in the order they were generated.”

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: