-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Main thread var tagged not GC-safe #4744
Comments
From the manual:
So, by definition,
|
That's fine as a definition, but the code above doesn't use any threading - everything's in the main thread. This means that the same code that runs with --threads:off now doesn't compile with --threads:on, before you've even thought about creating a separate thread.
This problem actually arose because I wanted to run a separate thread completely isolated from every other thread with no communication at all, just as a background worker. The 'solution' I found, was to mark all variables declared in the main thread as {.threadvar.}, which seemed terribly unsatisfying and generally wrong. Putting the "routes:" inside a procedure, which is surely something you'd have to do if you wanted to follow the 'no globals' rule, causes C generation errors: import asyncdispatch, jester
proc main =
var hello: string
proc test(s: string): string =
result = s
routes: # error reported here
get "/":
resp test(hello)
main() There error in c generation that starts with:
Attempting to compiling this without --threads:on also causes the c-gen error. |
This is the result of a lambda lifting bug: #4088 . My workaround is in Jester's master branch, but not yet in the tagged version, so you would have to
|
Installed jester@#head and it does indeed fix running the routes macro inside a proc. Thanks a lot for informing me of this fix. Now I can compile the second code snippet above (calling Jester in a proc), which gets rid of the GC unsafe messages too! There is still the issue of the compiler throwing GC unsafe errors for module level code when the code is "technically thread safe" (though I got the impression this isn't trivial to exorcise), but placing in a proc is a way better work around than what I was doing before. |
There is now also a |
When compiled with --threads:on
Compiler reports:
c:\nim\lib\pure\asyncmacro.nim(264, 7) Hint: Processing match as an async proc. [User]
test.nim(8, 1) template/generic instantiation from here
c:\nim\lib\core\macros.nim(333, 70) template/generic instantiation from here
c:\nim\lib\pure\asyncmacro.nim(31, 8) Error: 'cb' is not GC-safe as it accesses 'nameIterVar' which is a global using GC'ed memory
Of course, the error is not in asyncmacro.nim.
The text was updated successfully, but these errors were encountered: