This post doesn't meet the requirements for a minimal, complete example and lacks some context, but isn't unsalvageable. Also, it's in a relatively unpopular pthread tag, so the bar for making the question appealing to attract answerers increases significantly.
Issues:
"I'm designing a circular buffer that reads a input text file and writes to output." Where is the text file? Questions that rely on user input or missing text files fail the reproducibility test and raise the annoyance bar for those providing assistance. If reading the file isn't integral to the problem you're having, you can minimize your question further by eliminating it.
If reading the file is integral, minimize the file and provide a snippet of it that reproduces the problem. This is particularly problematic in the c tag.
Same goes for the argv
array. If you hardcode args into the program with clear variables, you don't have to explain how to run the program, or worse still, not explain how to run the program and leave everyone to read the code to figure it out.
"It works by creating a pthread named Lift-R
and calls request_t()
to load values onto the buffer..." is confusing to me without knowing what problem the application is supposed to solve. I need more exposition. When you say "lift", I think "British elevator", which seems like a reasonable assumption. A sentence like "I'm writing a multithreaded application to simulate 3 elevators (lifts) in a hotel" or something like that goes a long way to clearing up contextual ambiguity.
- Your header has
#include "list.h"
, but what is list.h
? Clearly, this is a large helper file with a pretty mundane interface that would be noisy to post, but nonetheless, its absence makes it hard for people to drop the code into an editor and reproduce the problem. Remove any unused imports. If this is needed, it might be possible to write an example that hits the fundamental problem without it.
- "Attempts I've made was to add a second mutex lock to prevent collisions. I've also tried arranging
pthread_join()
to no avail." This ticks off the "what I've tried" box but is vague and hand-wavey. What pthread_join
arrangements did you try? Where and how did you use the second lock? How did they fail to solve the problem specifically? What did the output look like for these different code configurations?
"How can I get the code to cycle through all the pthreads that call lift()
until the input text file is empty." This seems like the key question you're asking, but there's no question mark. That might seem like a nitpick, but it does matter. Some askers bold or italicize their main question to make it stand out.
Again, I have no idea what's in the input text file, and while this sentence explains the desired behavior, I'm left unsure what the actual output of this behavior should look like. It's hard to take action on this.
- "NOTE: The code is currently in it's debugging phase." What does this mean? It seems unnecessary and distracting to mention, or an excuse for some of the noise in the code.
- The code itself is 118 lines. Granting that any multithreaded application in C is going to be pretty verbose, there is still room to minimize it as described above. There are a series of assertions in
main
that are probably non-critical. File IO and arguments and unused headers, as mentioned above, can be eliminated.
Also worth mentioning to explain the lack of answers is that multithreading problems and the tag pthread in particular tend to be pretty unpopular. They're a pain to answer. In many cases, multithreading debugging requests suffer from reproducibility problems and only a small set of Stack Overflow users know the technology, and those that do usually have their sights set higher.
The rewards for ultra-specific pthread questions are usually very small, too. These questions are unlikely to be widely searched or become canonical answers, so the best an answerer can hope for is +1 or +2 and a check mark and the question will often have 15 views a year later. These questions are generally asked by low rep users, which further dissuades prospective answerers. In many cases, they smell like homework, further exacerbating all of the problems mentioned above.
Long story short, getting pthread questions answered requires an extra effort to make it appealing, crisp and palatable. I recommend trying to generalize the problem to the extent you can and lower the pain threshold as much as possible. The question in its current state needs work to hit these marks.