CSC 216/s08/but one lamp: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 19: Line 19:


===Table Setup===
===Table Setup===
[[Image:VectorArrayPic.jpg]]
[[Image:VectorArrayPic.jpg]]<br>
Each team should have four square "variables", that represent either an Array or Vector.(Depending on previous knowledge and/or whether or not array resizing should be incorporated into the exercise) These Vectors are normal instance variables for the single student team. For the 5 student team, the Vectors are instance variables of the Driver and therefore shared variables amongs the threads.
Each team should have four square "variables", that represent either an Array or Vector.(Depending on previous knowledge and/or whether or not array resizing should be incorporated into the exercise) These Vectors are normal instance variables for the single student team. For the 5 student team, the Vectors are instance variables of the Driver and therefore shared variables amongs the threads.



Revision as of 20:30, 15 April 2008

Formatting Resources

Formatting Help Guide from MetaWiki

An Introduction to Threads

This project will introduce threads to students who have no previous knowledge on the subject.

What are Threads?

Threads are a way to break up your machine's processing so it can do many tasks all at the same time. These tasks are able to share variables, monitor each other’s progress, and begin and terminate separately.

Participants and props

For this too work, six students with a healthy desire for competition must be chosen from the class.

The only required materials are two decks of playing cards and a table to sit around.

How it works

Table Setup


Each team should have four square "variables", that represent either an Array or Vector.(Depending on previous knowledge and/or whether or not array resizing should be incorporated into the exercise) These Vectors are normal instance variables for the single student team. For the 5 student team, the Vectors are instance variables of the Driver and therefore shared variables amongs the threads.

First the teacher should get out two decks of cards, remove the jokers, and shuffle well. He should then get a single volunteer from the class and hand him one of the decks. Next, the teacher should find five more students ready to compete against the other student giving one of the other students the second deck. The teacher will instruct the single student that when he says go, that student should sort the card into suite and then from 2 to Ace by suite. He will then instruct the group of five that when he says go, the student with the deck, the Driver, should count out exactly thirteen cards and give it to one of his fellow students, a thread. He should repeat until all the cards are given out. As soon as a thread gets a deck it may begin to sort it into suite and place it in the middle of the table where the threads shared variables go. The thread may not pick up any cards unless handed by the driver and may begin it's task as soon as it receives cards without having to wait. Once all threads have terminated the suite sort, the driver may then give each thread a stack to sort from 2 to Ace. The group of five people should finish much faster than the single person.

This simulation should show that by breaking up processing in this way, threads can accomplish some tasks faster than a single thread. The teacher should then go on to teach some of the more intricacies of threads.