/* * Thread.cpp * */ #include "Thread.h" #include "Program.h" #include "ReplicatedSecret.h" #include "Secret.h" #include "Yao/YaoGarbleWire.h" #include "Yao/YaoEvalWire.h" namespace GC { template void* Thread::run_thread(void* thread) { ((Thread*)thread)->run(); return 0; } template Thread::Thread(int thread_num, Machine& machine, Names& N) : machine(machine), processor(machine), N(N), P(0), thread_num(thread_num) { pthread_create(&thread, 0, run_thread, this); } template Thread::~Thread() { if (P) delete P; } template void Thread::run() { if (singleton) throw runtime_error("there can only be one"); singleton = this; secure_prng.ReSeed(); P = new Player(N, thread_num << 16); string input_file = "Player-Data/Input-P" + to_string(N.my_num()) + "-" + to_string(thread_num); processor.open_input_file(input_file); done.push(0); pre_run(); ScheduleItem item; while (tape_schedule.pop_dont_stop(item)) { processor.reset(machine.progs.at(item.tape), item.arg); run(machine.progs[item.tape]); done.push(0); } post_run(); MC.Check(*P); } template void Thread::run(Program& program) { while (program.execute(processor) != DONE_BREAK) ; } template void Thread::join_tape() { int _; done.pop(_); } template void Thread::finish() { tape_schedule.stop(); pthread_join(thread, 0); } template class Thread; template class Thread< Secret >; template class Thread< Secret >; template class Thread< Secret >; template class Thread< Secret >; template class Thread; } /* namespace GC */