Closed matkuki closed 6 months ago
Nim's ref object
is not thread safe so it must be used with extreme care if threads are being used (almost certainly going to be broken if global).
I am sorry that I cannot explain super deeply here, it is a deep topic, but you'll need to ensure all ref object
s are only ever instantiated and used in one thread (a handler call tree). This is because the reference count is not thread-safe or atomic. Some searching about Nim ref object
and threads and --mm:arc/orc will find some discussion on the Nim forums.
(I should also note that the error in your post does not appear to be related to the area of the code you're highlighting.)
Thanks.
I should also note that the error in your post does not appear to be related to the area of the code you're highlighting.
Correct, the problem is the indicated line, the error is for the router.get("/", index_handler)
call.
I just wanted to highlight that I had no idea what was wrong for quite some time, as the error message does not indicate where the problem is. In the original code I use the tim
library, which I didn't know returned a ref
object for generating HTML
code, so it was weird as I just changed one line and it stopped working:
proc index_handler(request: Request) =
var headers: HttpHeaders
headers["Content-Type"] = "text/html"
let content: string = timl.render("index")
request.respond(200, headers, $content)
So I guess tim
in not suited to for use with mummy
.
Hi,
This code uses a global
ref
object in theindex_handler
:which in turn throws this error:
This is a contrived example, in my original code I use the tim library which uses a
ref
object to generateHTML
templates, but it's the same problem.Is there a solution for this?