hi,
I need help in my work.
Let me give some idea of what I am trying to do.
I have multithreaded C program, where I am suppose to take inputs from different files (a input file for each thread). Threads will execute based on these inputs.
I am struggling in taking multiple inputs and assigning them to separate threads in program.
Can some help me in this.
Please feel free to ask is my problem statement is not clear.
-
ps

You mean you want to pass argv[1] to thread #1, argv[2] to thread #2 etc. ? Seems pretty trivial to me.

You mean you want to pass argv[1] to thread #1, argv[2] to thread #2 etc. ? Seems pretty trivial to me.

yeah.
ok
dats also fine.
./proggram -redir:file1 -redir:file2 -redir:file3 inputfile1+inputfile2+inputfile3
so here thread1 works on the input from file "inputfile1" and writes output to "file1" and so on.
after I create thread1 how to proceed next.
actually I have not done thread programming before. so I know that its trivial , but still new for me.
please help.

At least two ways to accomplish that
1) make a global char* array that is a duplicate of the argv parameter and let each thread access it.

2) pass an argument to the thread when the thread is created. Exactly how to do that depends on how you create the threads.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.