junrushao commented on PR #360:
URL: https://github.com/apache/tvm-ffi/pull/360#issuecomment-3690270762

   Below is from ChatGPT:
   
   ---------------------
   
   In practice, yes for Linux: if you use `std::mutex` you should expect your 
final link to include POSIX threads support.
   
   What that means concretely depends on your toolchain:
   
   * **GCC/libstdc++ and Clang using libstdc++ (common case):** you typically 
need to link with **`-pthread`** (preferred) or **`-lpthread`** (less complete).
   * **Modern glibc (“libpthread merged into libc” in glibc 2.34+):** even if 
`-lpthread` doesn’t show up as a distinct DSO at runtime, you still generally 
want **`-pthread`** because it also sets compile-time and link-time flags 
(e.g., defines/requires thread-safe runtime behavior), not just a library.
   
   Why you might not “see” it:
   
   * If you run `ldd` and **don’t see `libpthread.so.0`**, that does **not** 
necessarily mean you aren’t using pthreads; on newer glibc the symbols may come 
from `libc.so.6`. The important part is that you built/linked with the proper 
thread flags.
   
   Best practice
   
   * **Use `-pthread`**, not `-lpthread`.
   
     * `-pthread` affects both compilation and linking.
     * `-lpthread` is only “link this library” and can be insufficient in some 
situations.
   
   CMake
   
   ```cmake
   find_package(Threads REQUIRED)
   target_link_libraries(your_target PRIVATE Threads::Threads)
   ```
   
   So: `std::mutex` implies you are using the C++ threading library, which on 
Linux is implemented on top of pthreads; therefore you should link accordingly 
(typically via `-pthread` / `Threads::Threads`).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to