I have a transaction failing indefinitely for some reason, and I would like to use trace instructions inside. For example, to print the state of the MVar's before executing the 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
Would that make the program segfault or miss-behave?
As long as you use trace
for debug purposes only you should be OK. As a general rule, just assume that in the final production-ready version of your program there will be no trace
s around.
You will never observe segfaults from trace
. Its "unsafety" stems from it injecting observable effects in pure code. E.g., in STM, when a transaction retries, its effects are assumed to be rolled back. If trace
was used to send a message to the user, you can't roll that back. If the output of trace
triggers a missile launch, you will have to deal with international side effects. If trace
instead just signals the developer with "FYI, the code is doing X", this is not part of the core logic of the program, and is perfectly fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With