63 lines · cpp
1#include <cstdint>2#include <functional>3#include <mutex>4#include <thread>5 6std::mutex t1_mutex, t2_mutex;7 8struct test_data {9 uint32_t eax;10 uint32_t ebx;11 12 struct alignas(16) {13 uint64_t mantissa;14 uint16_t sign_exp;15 } st0;16};17 18void t_func(std::mutex &t_mutex, const test_data &t_data) {19 std::lock_guard<std::mutex> t_lock(t_mutex);20 21 asm volatile(22 "finit\t\n"23 "fldt %2\t\n"24 "int3\n\t"25 :26 : "a"(t_data.eax), "b"(t_data.ebx), "m"(t_data.st0)27 : "st"28 );29}30 31int main() {32 test_data t1_data = {33 .eax = 0x05060708,34 .ebx = 0x15161718,35 .st0 = {0x8070605040302010, 0x4000},36 };37 test_data t2_data = {38 .eax = 0x25262728,39 .ebx = 0x35363738,40 .st0 = {0x8171615141312111, 0xc000},41 };42 43 // block both threads from proceeding44 std::unique_lock<std::mutex> m1_lock(t1_mutex);45 std::unique_lock<std::mutex> m2_lock(t2_mutex);46 47 // start both threads48 std::thread t1(t_func, std::ref(t1_mutex), std::ref(t1_data));49 std::thread t2(t_func, std::ref(t2_mutex), std::ref(t2_data));50 51 // release lock on thread 1 to make it interrupt the program52 m1_lock.unlock();53 // wait for thread 1 to finish54 t1.join();55 56 // release lock on thread 257 m2_lock.unlock();58 // wait for thread 2 to finish59 t2.join();60 61 return 0;62}63