Avb Avb
Avb Avb

Reputation: 553

Linux thread execution flow

I am using pthread in Linux and I have implemented two classes (which inherit from another class which abstracts POSIX threads) running as threads. Thread1 is starting and stopping thread2. During thread2 is running, thread1 is calling a function of the thread2 class. My question is when thread1 is calling this function, when is it executed? is it executed just in time as it is called so that thread2 perform the operation of this method and continues afterwards where it stopped?

Upvotes: 1

Views: 203

Answers (2)

John Kugelman
John Kugelman

Reputation: 362087

Don't confuse classes and threads. Classes and threads are independent and unrelated concepts. Executing code from a different class will not cause that code to be run in a different thread. Any method called on thread X will run on thread X.

Upvotes: 3

diegoperini
diegoperini

Reputation: 1806

Threads execute callables which are in your case probably member functions. If you encapsulate a phtread in a class, only the corresponding member function becomes parallel, other calls to other member function would still run on the caller thread.

Upvotes: 1

Related Questions