首页 > 杂记 > 见过计算机题被和化学结合的吗(非算法题)

见过计算机题被和化学结合的吗(非算法题)

2009年4月4日

见过计算机题被和化学结合的吗,要是算法题也就罢了,结果还是关于多线程与并发的题目。。。

刚才在《多线程、并行与分布式程序设计基础》这本书上看到这么一道习题5.9:

The Water Molecule Problem

Suppose hydrogen and oxygen atoms are bouncing around in space trying to group together into water molecules. This requires that two hydrogren atoms and one oxygen atom synchronize with each other. Let the hydrogen (H) and oxygen (O) atoms by simulated by processes or threads. Each H atom calls a procedure Hready when it wants to combine into a water molecule. Each O atom calls another procedure Oready when it wants to combine.

Your job is to write the two procedures, using semaphores for synchronization. An H atom has to delay in Hready until another H atom has also called Hready and one O atom has called Oready. Then one of the processes (say the O atom) should call a procedure makeWater. After makeWater returns, all three processes should return from their calls of Hready and Oready. Your solution should not use busy waiting and it must avoid deadlock and starvation.

This problem is taken from (Exercise 4.25, page 198):

Foundations of Multi-threaded, Parallel, and Distributed Programming
Gregory Andrews
Addison-Wesley 2000
ISBN 0-201-35752-6

orz….

杂记

  1. 目前还没有任何评论.
  1. 目前还没有任何 trackbacks 和 pingbacks.