ModularM
Modular17mo ago
5 replies
Martin Dudek

parallelize and @parameter issue in Mojo 24.5

I am trying to convert my projects to Mojo 24.5. Right now I face the following issue.

When running

from algorithm import parallelize

fn main():
    var t = 5
    @parameter
    fn whatever(ip:Int):
        print(t)
    parallelize[whatever](1)


I get 4507533440 printed as result.

In the @parameter doc https://docs.modular.com/mojo/manual/decorators/parameter it says

This is an unsafe feature because we currently do not model the lifetimes of capture-by-reference.

but up to 24.4 i never had this issue. Did i miss some fundamental change here? Any advice how to handle this would be great. Thx 🙏

ps
adding

  '_ = t' 


at the end of this demo would solve the issue but that gets complicated and ugly in my projects ...
Executes a function or if statement at compile time.
@parameter | Modular Docs
Was this page helpful?