Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Press Ctrl + if the image is too small! Thank you! Consider the following cade t

ID: 3902948 • Letter: P

Question

Press Ctrl + if the image is too small! Thank you!

Consider the following cade that creates N threads using the POSIX threading library. The thread function threadFun receives as parameter a thread index (fram O to N-1) Hefi e NTHREADS 4 number of test threeds // ren nder ot the tunction 15 irrelevent t0" th15 question eid sain) int 1; pthreed-t tid| pthrend attr attr pthreed sttr init tr) ...renoinder o the furction is irrelev fer this question What is the right set of statements for LINE A and LINE B that correctly initialize the thread index variable from 0 to N-1, regardless of the timing of cach thread's scheduling HINT: watch for memory that can be modified inadvertently by other threads. UINE B pthresd createl&tidi;] attr, threadFun woid"li O LINE A indx-intyp LINE B pthresd createl&tidlil; &attr;, threadFun loid"li UNE A index-1inth. LINE B pthred createl&tidil; &attr;, threadFun &i; UINE A index-it)o UNE B: pthread-crestel&tidli;], &attr;·threadFun &i;: D Question 8 12.5 pts What does NOT belong specifically to a thread, but is shared by all threads of a process: ? stack program counter heap G contents of the general purpose registers G data section

Explanation / Answer

7)

If you have any doubts, please give me comment...

Ans: LINE A: index = (int)p;

LINE B: pthread_create(&tid[i], &attr, threadFun, (void*)i);

Syntax to create thread:

8)

Ans: A(Stack)

threads share all segments except the stack. Threads have independent call stacks, however the memory in other thread stacks is still accessible and in theory you could hold a pointer to memory in some other thread's local stack frame.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote