I take this question of the The Linux Programming Interface:
I want someone to explain the under line statement because it sounds complex to me couldn't understand anything
30-1 Modify the program (thread_incr.c) so that each loop in the thread’s start function outputs the current value of glob and some identifier that uniquely identifies the thread.
Run the program, redirecting output to a file, and then inspect the
file to see what happens to glob as the kernel scheduler alternates execution between the
two threads.
Last edited by jim mcnamara; 12-22-2012 at 09:48 PM..
What they're talking about with the pointer is, whenever you create a thread, you are giving it a pointer to something. The function "called" by the new thread has that value passed into it -- that's why it takes any value at all, instead of being void.
It can be whatever you want, and is always there. If you're not passing data into it, you're probably just giving it NULL. If you wanted to pass each thread something different, be sure to not give them the same variable -- they'll all end up pointing to the same thing, they won't get unique values. To be different it needs to literally be different memory. You could give them different elements of an array, for example. Memory fresh from malloc() also works.
Of course, threads have their own unique ID's in the first place, so it's a bit redundant to give it your own unique number, but that's why this is an exercise.
Well, you can pass it a pointer to a struct or object with an id and everything else you want to initialize it with and potentially communicate to it with.
Is it an exercise in finding out the student knows a) about thread ids, or is it about b) passing to the thread at creation time, never mind c) the distributed approach of checking one out from a mutex integer? The mutex integer, especially in an object, can have a corresponding array of pointers where the thread can hang a struct of all the data it is involved in for global access. The object interface method can ensure the array is large enough to hold the current number of this applications thread struct pointers. Distributed generation of the struct, array entry lightens the load on the master thread at startup. Since we are in thread land, it is time to think about parallelism and delegated tasks.
Dear all,
I am having a huge XML file, as below structure
<EMPLOYEE>
<RECORD id =aaa>
<Salary>99999</Salary>
<section>ssss</section>
</RECORD>
<RECORD id =bbb>
<Salary>77777</Salary>
<section>ssss</section>
</RECORD>
</EMPLOYEE>
This is a 50 GB file I want to read this file in... (9 Replies)
hello to all
i want to use multithreading to my UDP broadcast server client program. will anyone help me by proving C code. i am working in fedora. also my requirement is POSIX compliance.please help me..... (6 Replies)
hello to all
i want to use multithreading to my UDP broadcast server client program. will anyone help me by proving C code. i am working in fedora. also my requirement is POSIX compliance.please help me..... (0 Replies)
Situation:
i have multiple pthread_create calls like this:
pthread_create(...., ThreadFunc1,.....);
pthread_create(...., ThreadFunc2,.....);
.
.
which i am using to create multiple threads.All the "ThreadFunc<i>" functions are actually calling same function "Receive" of a class using same... (3 Replies)
Hi
I need to insert 1million records into MySQL database, but it is taking lot of time as there is no bulk insert support.
I want to spawn 10 processes which will insert 100k records each parallely.
Can somebody help me with a example program to execute this task through shell scripting. (5 Replies)
Hi all, I have a query about multithreading. What I would like to do is, at the start of my main update() function, start a couple of threads in parallel, once they are all complete carry on with my main update function.
void update() {
thread1->update(); // fluid solver
... (3 Replies)
:confused:
Hi!
I have created a Multhreaded Application in Pro*C (using pthreads) with about 5 Threads running simultaneously. The Application is basically to Update a Centralized Table in Oracle, which updates different rows in the Table (Each Thread updates different rows!). The... (16 Replies)