Is it safe to use tracing in STM-stransaction?

For some reason, my transaction is failing, and I would like to use the trace instructions inside. For example, to print the MVar state before executing a transaction in this fragment:

data_out <- atomically $ do rtg_state <- takeTMVar ready_to_go JobDescr hashid url <- T.readTBChan next_job_descr case rtg_state of Ready_RTG n -> do putTMVar ready_to_go $ Processing_RTG n putTMVar start_harvester_browser hashid putTMVar next_test_url_to_check_chan hashid putTMVar next_harvest_url hashid return (n,hashid,url) _ -> retry 

Does segfault or miss-behave do this?

+8
haskell stm
source share
1 answer

While you are using trace for debugging purposes, you should be fine. As a rule, just assume that the final version of the finished version of your program will not have trace .

You will never see segfaults from trace . Its “insecurity” is due to the fact that it introduces observable effects into clean code. For example, in STM, when a transaction retries, its effects are considered rollback. If trace was used to send a message to the user, you cannot drop it. If the trace output triggers a rocket launch, you will have to deal with international side effects. If trace instead simply signals the developer that “FYI, the code is executing X”, this is not part of the core logic of the program, and it’s fine.

+9
source share

All Articles