003 Linux System ProgrammingIssues, queries and suggestions related to Linux, Linux Programming, IPC, Interprocess Communication, Synchronization, Semaphore, System Programming, Linux Software Development.
Threads are meant to be run concurrently until exited. They could be initiated in a for or while loop. They are meant for parallel processing running independently of one another. They remain in suspended state when synch has been applied to them & keep waiting for data to arrive until terminated only after the terminal is closed.
A program if consists of few threads & they are in sequence , it is pretty much apparent that some will execute faster as compared to others. If this happens and not in the order of sequence then threads may block themselves waiting for data to come from other dependent threads.
This could be resolved by making faster threads to sleep for some time till the execution of other threads.
Thread attributes define the properties and characteristics of a thread, encompassing aspects like creation, polling, joining, and exit code handling. They play a crucial role in fine-tuning and optimizing multi-threaded applications, enabling programmers to control performance, resource management, and synchronization for more efficient concurrent program execution.
The exact set of thread attributes and how to manipulate them may vary from one system to another. Linux follows the POSIX threads (pthread) standard for managing threads, there may still be some variations and extensions in the threading library or system-specific features. Therefore, it's important to refer to the documentation and guidelines provided by the Linux distribution in order to how to manipulate the thread attributes effectively in that particular environment.
In order to create a thread, we need to use a function called pthread_create() and at the end it must be joined using the function pthread_join() and while compiling use -lpthread during compilation as it includes the library pthread.h.