Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
300 views
in Technique[技术] by (71.8m points)

c++ - Multiple instances of the same application hang when they launched with terminal on Mac

I have multithreaded Qt application and I want to launch several instancies of it.

  1. I launch 3 instances of my application with terminal on Mac OS X 10.15.4. (./myapp/Contents/MacOS/myapp)
  2. All my applications hang on the same mutex.
  3. I create a spindump with Activity monitor for each of them
  4. I see that all spindumps have aproximately the same content (thread ids, objects addresses and so on) except process' ids.

I can also see that my mutex is called once for one thread in each application. All spindumps have equal call stacks, addresses, ids:

Thread 0x3e6702    Thread name "working_thread"    1000 samples (1-1000)    priority 31 (base 31)
...
std::__1::recursive_mutex::lock() + 9 (libc++.1.dylib + 222839) [0x7fff6d45f677]
_pthread_mutex_firstfit_lock_slow + 222 (libsystem_pthread.dylib + 6455) [0x7fff7035d937]
__psynch_mutexwait + 10 (libsystem_kernel.dylib + 12386) [0x7fff702a1062]
psynch_mtxcontinue + 0 (pthread + 9566) [0xffffff7f82b2e55e] (suspended, blocked by turnstile waiting for myapp [51272] [unique pid 1045970] thread 0x3e881c)

Why does it happen? Is my mutex shared between apps?

question from:https://stackoverflow.com/questions/66064974/multiple-instances-of-the-same-application-hang-when-they-launched-with-terminal

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

No. Memory spaces of different processes are unconnected (mostly).

There is a technique called ASLR (address space layout randomization) that exists to make addresses less predicable, as buffer overflow exploits are easier if addresses are predictable. Barring that, addresses will be quite similar.

Modern OS' give each process a unique virtual memory space. Sometimes they share a kernel memory space. But the address of a stack allocated mutex (or even a heap one) may be identical on two programs that have run the same steps.

There are OS' where different processes share the same memory space. They tend to be old, or for very small computers, and not used on desktop computers.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...