Skip to content
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

Thread & Worker should not be ThreadSafe objects #141

Open
dktapps opened this issue Apr 2, 2024 · 0 comments
Open

Thread & Worker should not be ThreadSafe objects #141

dktapps opened this issue Apr 2, 2024 · 0 comments

Comments

@dktapps
Copy link
Member

dktapps commented Apr 2, 2024

It doesn't really make any sense for these objects to be shared.
They contain API methods which are only intended for the parent thread to use, such as start(), join(), isRunning(), isJoined(), etc.

The only reason a shared context object is desirable for these things is to allow Thread::run() to get information from the parent thread.
After the initial run(), it makes more sense to put things in static properties, rather than paying a performance penalty to access them from the thread context again and again.

Proposal:

  • Make Thread and Worker no longer extend ThreadSafe
  • Make Thread and Worker become final
  • Make Thread accept a Runnable in its __construct() (which will be thread-safe), which it runs and then immediately shuts itself down (contrary to a Worker, which remains running - though we could easily ditch Thread and only have Worker with this system)
  • Possibly introduce ClosureRunnable
  • Move Thread::getCreatorId() to Runnable::getCreatorId()
  • Remove Thread::getCurrentThread() and Thread->getThreadId() (Thread::getCurrentThreadId() will remain)
  • Add Thread::getName() and Thread::setName() for identification (relates to API to set thread name seen by htop etc #139)
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

No branches or pull requests

1 participant