<commit_before>
require 'thread'

class RestCore::Future::FutureThread < RestCore::Future
  def initialize *args
    super
    self.condv = ConditionVariable.new
    self.mutex = Mutex.new
  end

  def wrap
    Thread.new{ yield }
  end

  def wait
    # it might be awaken by some other futures!
    synchronize{ condv.wait(mutex) until loaded? }
  end

  def resume
    condv.broadcast
  end

  protected
  attr_accessor :condv, :mutex

  private
  def synchronize; mutex.synchronize{ yield }; end
end<commit_msg>future_thread.rb: double loaded? check to avoid locking. status should<commit_after>
require 'thread'

class RestCore::Future::FutureThread < RestCore::Future
  def initialize *args
    super
    self.condv = ConditionVariable.new
    self.mutex = Mutex.new
  end

  def wrap
    Thread.new{ yield }
  end

  def wait
    # it might be awaken by some other futures!
    synchronize{ condv.wait(mutex) until loaded? } unless loaded?
  end

  def resume
    condv.broadcast
  end

  protected
  attr_accessor :condv, :mutex

  private
  def synchronize; mutex.synchronize{ yield }; end
end
{'fraction_non_alphanumeric': 0.07531760435571688, 'fraction_numerical': 0.0, 'mean_word_length': 3.291828793774319, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '243131', 'n_tokens_mistral': 356, 'n_tokens_neox': 342, 'n_words': 109}