title: How to exit a forkIO thread when it excutes a loop procedure
body: <p>I'm writing something like a music player and get stuck with the playback progress bar.</p>
  
  <p>In my program when the play button is clicked, I use forkIO to fork a thread which controls the progressbar. However, the forked thread now executes a loop. How can I inform that thread to terminate when I stop current song or change songs.</p>
  
  <p>I've been trying to use IORef Var, for example </p>
  
  <p><code>flag &lt;- newIORef False</code></p>
  
  <p><code>forkIO $ progressBarFunc flag</code></p>
  
  <p>and in the function <code>progreeBarFunc</code> it checks whether flag is true and decides to exit loop or not. </p>
  
  <p>But this does not work.</p>
  
  <p>More generally, how can I tell the forked thread to stop when I use forkIO to fork threads?</p>
  
  <p>In addition, if I have an IORef Var and pass it to the function in forkIO, do the main thread and the forked thread share the same IORef Var or the forked thread actually has a copy of it?</p>