Is it possible to create multiple jobs with in a single thread? I am really wondered by looking into one of the product logs. Same thread called a function with different parameter approximately at the same time.
Please correct me if understanding is wrong. or is there any other method which actually does this in a single thread.
If you mean by “multiple jobs” the concept of “multiple threads”, then yes … it is possible to create multiple threads from a single thread … you simply call
pthread_create()in your thread, and it will spawn more threads.From your description of some reading of a “log file” though, it sounds to me like you’re asking whether a single thread can do multiple things simultaneously. The answer to that is “no”. A single thread of execution has the appearance of sequential consistency to the end-user, meaning that it will appear to perform one operation after another. When you are stating from a log-file that a single thread appeared to call one function at the same time as another function, but with different parameters, the most likely cause for this scenario is that the precision of time measurement for the log file was not precise enough to account for how fast the function calls took place. Therefore it appears as though two function calls were made simultaneously by a single thread. That does not mean that a single-thread is performing “multiple jobs” simultaneously … that would be impossible.