Cast to program is not thread-safe.

Imported from http://bugzilla.roxen.com/bugzilla/show_bug.cgi?id=7783

Reported by @grubba

Running

  string filename;
  program p = (program)filename;
  p(@args);

in two concurrent threads on the same filename may cause one of the threads to fail with eg "Attempting to clone an unfinished program".