multithreading - Peterson's Algorithm with Threads and Linked List (C language) -


i have following situation:

first of all, created int linked list (already working, no problems this) , need perform following task:

using 2 threads, 1 thread remove first element of list , after same thread must add new element @ end of list (the list follows fifo structure).

the second thread same: delete first element , add 1 @ end of list.

i need perform operation more once, done using loop.

when create thread, use following function:

for(i=0, i<num_threads; i++)     pthread_create (&thread[i], null, threadbody, (void *) i); 

in num_threads variable containing number of threads use (in case, 2), , thread declared as:

pthread_t thread [num_threads] ; 

so, questions are:

do need perform operations i've meant before (add , delete elements on list) on threadbody function or function empty?

in case threadbody function isn't meant operation, how use threads i've created perform operations? done using pthread_join function?

another point need use peterson's algorithm in order guarantee mutual exclusion. how do it?

i can see operations on linked list simple. in such context, maybe better use lock-free programming. read, review link. if using gcc, please review __sync_bool_compare_and_swap operations (link). finally, problem of programming lock-free linked list has been broadly studied. next link may give hints link. luck!


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -