第4章 練習問題 1-2

1 スレッドの意味

(a)
local B in
   thread 
      B=true  % (1)
   end
   thread 
      B=false % (2)
   end

   if B then % (3) if文
      {Browse yes} %(4) Browse
   end
end

のように番号を付ける。3と4は順序を保持する必要がことを考慮にいれると、次のようになる。

  • 1-2-3-4
  • 1-3-2-4
  • 3-1-2-4
  • 2-1-3-4
  • 2-3-1-4
  • 2-3-4-1
  • 3-1-2-4
  • 3-2-1-4
  • 3-1-4-2
  • 3-2-4-1
(b)
local B in
   thread 
      try B=true catch _ then skip end
   end
   thread 
      try B=false catch _ then skip end
   end

   if B then {Browse yes} end
end

2 スレッドとガーベッジコレクション

そもそも、{Wait _}がブロックされたままなので、{A}の呼び出しは終了しないと思う。問題の意図が分からない。