Skip to content

hold evalLock while computing tostring#410

Open
davidkoski wants to merge 3 commits into
mainfrom
description-lock
Open

hold evalLock while computing tostring#410
davidkoski wants to merge 3 commits into
mainfrom
description-lock

Conversation

@davidkoski
Copy link
Copy Markdown
Collaborator

Proposed changes

  • tostring internally calls eval, which is not thread safe

Observed while investigating ml-explore/mlx-swift-lm#291

(lldb) bt
* thread #12, name = '[Swift Testing] test gemma3nAttentionTest2() - running (Task 160)', queue = 'com.apple.root.user-initiated-qos.cooperative'
    frame #0: 0x000000018a037ae0 IOKit`iokit_user_client_trap + 8
    frame #1: 0x0000000192317184 IOSurface`-[IOSurfaceSharedEvent waitUntilSignaledValue:timeoutMS:] + 72
    frame #2: 0x00000001105f3464 MLXLMTests`bool NS::Object::sendMessage<bool, unsigned long long, unsigned long long>(pObj=0x0000000a6911ebc0, selector="waitUntilSignaledValue:timeoutMS:", args=1, args=18446744073709551615) at NSObject.hpp:216:16
    frame #3: 0x00000001105f3438 MLXLMTests`MTL::SharedEvent::waitUntilSignaledValue(this=0x0000000a6911ebc0, value=1, milliseconds=18446744073709551615) at MTLEvent.hpp:154:12 [inlined]
    frame #4: 0x00000001105f3404 MLXLMTests`mlx::core::Event::wait(this=0x0000000a68b23738) at event.cpp:25:14
    frame #5: 0x000000010fbb8f80 MLXLMTests`mlx::core::array::wait(this=0x0000000170029a30) + 124
    frame #6: 0x0000000110937080 MLXLMTests`mlx::core::eval(outputs=size=0) at transforms.cpp:324:40
    frame #7: 0x000000010fbb9044 MLXLMTests`mlx::core::array::eval(this=0x0000000170029bc0) + 156
    frame #8: 0x00000001109625d0 MLXLMTests`mlx::core::operator<<(os=0x0000000170029be0, a=array @ 0x0000000170029bc0) + 56
  * frame #9: 0x000000010fafa4c4 MLXLMTests`::mlx_array_tostring(str_=<unavailable>, arr=<unavailable>) + 104
    frame #10: 0x000000010fa56190 MLXLMTests`MLXArray.description.getter() + 244

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

- tostring internally calls eval, which is not thread safe
@davidkoski davidkoski requested a review from angeloskath May 18, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant