Hello
My teacher gave me sample code of a linked list thats not thread safe and told me to use pthreads mutex to make it thread safe
Sample code:
The other given functions are insert and delete.Code:// routine to return the data from the node with the given key. long listSearch(listNodePtr listPtr, long key) { listNodePtr currPtr; long result; currPtr=listPtr; while (currPtr!=NULL) { if (currPtr->key==key) { // As you convert this code for threads, result=currPtr->data; // think about why I didn't just code return(result); // 'return(curr->data)' in this if statement. } else { currPtr=currPtr->next; } } return (-1); // indicates "not found" } // end listSearch
I want to understand his comment asking why he didn't just return curr--> data directly.
im assuming the issue is that if another thread inserts/deletes that will affect search.
But not sure how that variable result helps.