Skip to content

feat: Detect incorrect multi-threaded use from c based ffi - #499

Merged
Anand Krishnamoorthi (anakrish) merged 1 commit into
microsoft:mainfrom
anakrish:ffi-thread-safety
Nov 17, 2025
Merged

feat: Detect incorrect multi-threaded use from c based ffi#499
Anand Krishnamoorthi (anakrish) merged 1 commit into
microsoft:mainfrom
anakrish:ffi-thread-safety

Conversation

@anakrish

Copy link
Copy Markdown
Collaborator

No description provided.

@anakrish
Anand Krishnamoorthi (anakrish) force-pushed the ffi-thread-safety branch 4 times, most recently from 2ffb382 to 1b37c84 Compare November 8, 2025 02:04
@anakrish
Anand Krishnamoorthi (anakrish) force-pushed the ffi-thread-safety branch 4 times, most recently from 3ab9d89 to 5634f90 Compare November 17, 2025 18:12
@anakrish
Anand Krishnamoorthi (anakrish) marked this pull request as ready for review November 17, 2025 18:17
@dpokluda

David Pokluda (dpokluda) commented Nov 17, 2025

Copy link
Copy Markdown

fclose (f);

nit: is it just me or is the indentation corrupted here? #Closed


Refers to: bindings/c-nostd/main.c:26 in 6d97651. [](commit_id = 6d97651, deletion_comment = False)

Comment thread bindings/ffi/src/engine.rs

@dpokluda David Pokluda (dpokluda) left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@anakrish

Copy link
Copy Markdown
Collaborator Author

fclose (f);

nit: is it just me or is the indentation corrupted here?

Refers to: bindings/c-nostd/main.c:26 in 5634f90. [](commit_id = 5634f90, deletion_comment = False)

Good catch. I see it too. My guess is that it is due to tabs vs spaces. I will use vscode to format it.

Add runtime detection for shared handle misuse

wrap the FFI engine handle with parking_lot::RwLock when the new
contention_checks feature is enabled, surfacing a clear “handle is already
in use” error instead of allowing undefined behavior
keep the feature optional so no_std builds or environments that supply
their own synchronization can opt out
caution users that this guards the handle itself but does not make the
engine’s operations globally thread-safe on its own

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>

@dpokluda David Pokluda (dpokluda) left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@anakrish
Anand Krishnamoorthi (anakrish) merged commit 688e612 into microsoft:main Nov 17, 2025
41 checks passed
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.

2 participants