Skip to content

rust: thread: Add Thread wrapper#109

Open
fbq wants to merge 2 commits intoRust-for-Linux:rustfrom
fbq:dev/thread
Open

rust: thread: Add Thread wrapper#109
fbq wants to merge 2 commits intoRust-for-Linux:rustfrom
fbq:dev/thread

Conversation

@fbq
Copy link
Member

@fbq fbq commented Mar 15, 2021

It's working (on my machine), but sure, a lot to improve.

Updates (v9):

  • Fix the potential memory leak found by @wedsonaf .
  • Now we have two thread structure: RawThread and Thread<ThreadArg>, each thread struct has its own try_new function. try_new_closure is now kernel::thread::spawn.
  • Other minor fixes.

Updates (v8):

  • Rebase to the latest rust/rust.

Updates (v7):

  • Rebase to the latest rust/rust to adopt sampe code changes.

Updates (v6):

  • Fix style and typo as suggestions from @ojeda
  • Add the case where a DST is shared between threads in examples, where try_new_closure() is slightly more appropriate than try_new().
  • Fix a bug: the ThreadArg parameter of try_new() should have 'static lifetime, because the new thread may live longer.

Updates (v5):

  • Make ThreadArg more easily to merge with PointerWrapper
  • Take the suggestion from @ojeda on the function names (I still keep the try_ prefixes, as that indicates the return type is KernelResult not Thread
  • Add the documentation section of "Memory Cost" for try_new_closure, so that the users will know the current drawbacks.

Updates (v4):

  • Don't use macro to generate bridge functions
  • Still surface try_new_c_style.

Updates (v3):

  • Multiple document and style fixes
  • Renames Thread::new to Thread::try_new because as the return type suggests the creation may fail.
  • Adds Thread::try_new_c_style to allow people use C function pointer for thread creation.
  • Moves the name parameter as the first parameter of Thread::try_new

Update:

  • Documentation is added ;-)
  • Thread::stop is added, to support waiting for a thread to finish.
  • Correctly handle the refcount of the task_struct. during Thread::new and Thread::drop.
  • Now Thread::new accepts FnOnce() -> KernelResult<()> as the closure for kernel threads.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

6 participants