# work0701.rb require 'thread' memory = "10100101011010" cs = Mutex::new showflag = true Thread::fork{ loop{ cs.synchronize{ if showflag == false puts memory showflag = true end } } } Thread::fork{ loop{ sleep(0.5) cs.synchronize{ if showflag == true if memory.gsub!(/001/,"000") showflag = false end end } } } Thread::fork{ loop{ sleep(0.5) cs.synchronize{ if showflag == true if memory.gsub!(/010/,"000") showflag = false end end } } } Thread::fork{ loop{ sleep(0.5) cs.synchronize{ if showflag == true if memory.gsub!(/100/,"000") showflag = false end end } } } Thread::fork{ loop{ sleep(0.5) cs.synchronize{ if showflag == true if memory.gsub!(/110/,"111") showflag = false end end } } } Thread::fork{ loop{ sleep(0.5) cs.synchronize{ if showflag == true if memory.gsub!(/101/,"111") showflag = false end end } } } Thread::fork{ loop{ sleep(0.5) cs.synchronize{ if showflag == true if memory.gsub!(/011/,"111") showflag = false end end } } } loop{ }