Question: CODING GUIDES( PYTHON ONLY): 1. Use of proper variables. 2. Use of proper function for each module. 3. No PLAGIARISM- CODE SHOULD NOT BE AVAILAIBLE
CODING GUIDES( PYTHON ONLY):
1. Use of proper variables.
2. Use of proper function for each module.
3. No PLAGIARISM- CODE SHOULD NOT BE AVAILAIBLE ON OTHER SITES
4. Write SIMPLE Code with COMMENTS.



QUESTION:

NOTE:
1) CODE IN PYTHON ONLY
2) SIMPLE WITH COMMENTS AND NOT COPIED CODE.
3) EXPLAIN CODE IN ANSWER ALSO.
THANKYOU...
Threads: It allows us to create multiple threads for concurrent process flow. It is most effective on multiprocessor or multi-core systems where threads can be implemented on a kernel-level for achieving the speed of execution pthread_create: used to create a new thread Parameters: - thread: pointer to an unsigned integer value that returns the thread id of the thread created. - attr: Set to NULL for default thread attributes. - start_routine: pointer to a subroutine that is executed by the thread. The return type and parameter type of the subroutine must be of type void *. The function has a single attribute but if multiple values need to be passed to the function, a struct must be used. - arg: pointer to void that contains the arguments to the function defined in the earlier argument pthread_exit: used to terminate a thread void pthread_exit(void *retval); Parameters: This method accepts a mandatory parameter retval which is the pointer to an integer that stores the return status of the thread terminated. The scope of this variable must be global so that any thread waiting to join this thread may read the return status. pthread_join: used to wait for the termination of a thread. int pthread_join(pthread_t th,void **thread_return); Parameter: This method accepts following parameters: - th: thread id of the thread for which the current thread waits. - thread_return: pointer to the location where the exit status of the thread mentioned in th is stored. pthread_t pthread_self(void); pthread_equal: compares whether two threads are the same or not. If the two threads are equal, the function returns a non-zero value otherwise zero. int pthread_equal(pthread_t t1, pthread_t 2 ) Parameters: This method accepts following parameters: - t1 : the thread id of the first thread - t2: the thread id of the second thread pthread_detach: used to detach a thread. A detached thread does not require a thread to join on terminating. The resources of the thread are automatically released after terminating if the thread is detached. int pthread_detach(pthread_t thread); Example 1: Example 2: \begin{tabular}{|l|} \hline int main() \\ \{ \\ std::thread t(\&thread_function); \\ std::cout "main thread \ n"; \\ //t.join(); \\ t.detach(); \\ return 0; \\ \} \end{tabular} Example 3: \begin{tabular}{l} \hline \#include \\ \#include \\ \#include \\ void thread_function(std::string s) \\ \{ \\ std::cout "thread function "; \\ std::cout "message is = " s
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
