9.15.2009

A thread is Like a Golf Course..

Conceptually, a thread is a flow of control within a program. A thread is similar to the more familiar notion of a process, except that multiple threads within the same application share much of the same state--in particular, they run in the same address space. It's not unlike a golf course, which can be used by many players at the same time. Sharing the same address space means that threads share instance variables, but not local variables, just like players share the golf course, but not personal things like clubs and balls.

Multiple threads in an application have the same problems as the players sharing a golf course: in a word, synchronization. Just as you can't have two sets of players blindly playing the same green at the same time, you can't have several threads trying to access the same variables without some kind of coordination. Someone is bound to get hurt. A thread can reserve the right to use an object until it's finished with its task, just as a golf party gets exclusive rights to the green until it's done. And a thread that is more important can raise its priority, asserting its right to play through.


but a thread is not like a golf course coz a thread isn't fun! makes you get eye bags and lets you sleep till midnight studying for the next day's exam! motiurok na jud ko!

credits: http://oreilly.com/catalog/expjava/excerpt/index.html#EXJ-CH-6-SECT-1

No comments:

Post a Comment