Skip to content

Remove stack allocated lock acquisition - #47

Open
ccp-serpent wants to merge 1 commit into
carbonengine:mainfrom
ccp-serpent:remove-locks-from-queuechannel
Open

Remove stack allocated lock acquisition#47
ccp-serpent wants to merge 1 commit into
carbonengine:mainfrom
ccp-serpent:remove-locks-from-queuechannel

Conversation

@ccp-serpent

@ccp-serpent ccp-serpent commented Sep 4, 2026

Copy link
Copy Markdown
Member

This change should not affect behavior. These locks aren't declared outside stack scope so there is no means by which another thread could attempt to acquire the same lock.

Summary

AI assistance disclosure

None

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup (no behaviour change)
  • Documentation
  • Build, CI, or tooling
  • Breaking change (public API or ABI)
  • Other (describe below)

Linked issue (optional)

No linked issue. But a question was brough up here which resulted in this work.

What changed

  • Removed stack allocated lock acquisition in QueueChannel objects.

Testing

  • The changes are covered in unit tests and passed successfully in a local environment. No further tests were added.

Platforms tested

  • Windows
  • macOS
  • Not applicable

Screenshots / captures

Checklist

  • I've read CONTRIBUTING.md.
  • My commits follow the commit-message style described there.
  • I've added or updated tests where it made sense.
  • I've updated docs / inline API comments for any behaviour change.
  • My CLA / ICLA is signed (the bot will let you know if it isn't).

This change should not affect behavior. These locks aren't declared outside stack
scope so there is no means by which another thread could attempt to acquire the
same lock.

@CCP-Aporia CCP-Aporia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Interesting! So, threading.Lock() was indeed wrong here. However, now the class is no longer thread-safe. A likely use case is that this kind of class is used to communicate between threads - a use-case that is supported by Stackless' channel implementation. Without any kind of lock - or with the previous stack-based lock - then this is going to cause data races.

@ccp-serpent

Copy link
Copy Markdown
Member Author

Interesting! So, threading.Lock() was indeed wrong here. However, now the class is no longer thread-safe. A likely use case is that this kind of class is used to communicate between threads - a use-case that is supported by Stackless' channel implementation. Without any kind of lock - or with the previous stack-based lock - then this is going to cause data races.

Don't python threads require a GIL acquisition? If so, there can only ever be a single thread executing python bytecode at any time.

https://docs.python.org/3/library/threading.html#gil-and-performance-considerations

I can see a case where we might want to add a locking mechanism here for free-threaded builds.

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.

3 participants