0

I am developing a C++ so lib for Python use. In Python code, the handle of the lib is shared between multi processes (maybe via multiprocessing) and called. My question is:

  1. From the perspective of my lib, can being called from different processes be viewed as multi threading?
  2. If so, what thread is using by Python, is pthread or sth? Can I configure it?
  3. If not, what is really happening behind it.

Thanks in advance.

Nimrod
  • 2,908
  • 9
  • 20
  • 1
    Are you asking in order to know if you should use locks in your lib's single-threaded code? – Adam.Er8 Dec 28 '21 at 08:56
  • @Adam.Er8 yes, I am doing sth around thread-safe. I think it's necessary? – Nimrod Dec 28 '21 at 09:10
  • 1
    Multiprocessing and multithreading are two different things. Regardless of which is being used, shared resources must be protected via mutexes like locks to prevent concurrent access to them. – martineau Dec 28 '21 at 09:28
  • @martinroblem.eau I agree with you on the difference between multi-threading and muti-processing. but it doesn't solve my problem – Nimrod Dec 28 '21 at 09:37
  • Then I guess I don't understand your question (nor does anyone else). – martineau Dec 28 '21 at 22:30
  • @martineau Sorry, bro. It's my bad. I am trying my best to make it clear. I know multi-processing and multi-threading are two different things, and I agree with you doing some thread-safe things both under multi-threading and multi-processing. I am wondering if calling my lib under a multiple thread circumstance (C++ test code) is exactly the same as calling from multi-processing Python? – Nimrod Dec 29 '21 at 01:37
  • Further, since `std::thread` can't set the priority, so I am trying to wrap it with some `pthread` api (Maybe like [this](https://stackoverflow.com/questions/18884510/portable-way-of-setting-stdthread-priority-in-c11/31652324#31652324) ) Is it possible for Python? – Nimrod Dec 29 '21 at 01:39

0 Answers0