traceToEvent :: History -> ThreadId -> Topped AccessNr -> Either String ([TraceRecord], History)
traceToEvent start tid limit =
    unsafePerformIO $ do worker <- getWorker False start
                         trc <- traceToEventWorker worker tid limit
                         rs <- replayStateWorker worker
                         killWorker worker
                         return $ let finalHist = appendHistory start $ HistoryRun tid $ Finite $ rs_access_nr rs
                                  in Right (trc, finalHist)
traceToEvent :: History -> ThreadId -> Topped AccessNr -> Either String ([TraceRecord], History)
traceToEvent start tid limit =
    unsafePerformIO $ do worker <- getWorker False start
                         trc <- traceToEventWorker worker tid limit
                         rs <- replayStateWorker worker
                         killWorker worker
                         return $ let finalHist = appendHistory start $ HistoryRun tid $ Finite $ rs_access_nr rs
                                  in Right (trc, finalHist)
traceToEvent start tid limit =
    unsafePerformIO $ do worker <- getWorker False start
                         trc <- traceToEventWorker worker tid limit
                         rs <- replayStateWorker worker
                         killWorker worker
                         return $ let finalHist = appendHistory start $ HistoryRun tid $ Finite $ rs_access_nr rs
                                  in Right (trc, finalHist)