Bug 459757 - pthread not working
pthread not working
Product: Fedora
Classification: Fedora
Component: glibc (Show other bugs)
All Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Fedora Extras Quality Assurance
Depends On:
  Show dependency treegraph
Reported: 2008-08-21 18:58 EDT by nishant.jain10
Modified: 2008-08-22 11:07 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2008-08-22 03:34:30 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
two c source code. (1.48 KB, application/x-gzip)
2008-08-21 18:58 EDT, nishant.jain10
no flags Details

  None (edit)
Description nishant.jain10 2008-08-21 18:58:47 EDT
Created attachment 314763 [details]
two c source code.

Description of problem:
This is actually related to pthreads not pth.Please redirect me if this is not the right place to file the bug.But problem is Fedora specific.
I have a code which produced unexpected erroneous result on fedora but same piece of code ran as expected on other linux distro(take ubuntu)..

The problem is pthread are not being created correctly, especially when more in numbers.The code(as attachment) is multithreaded matrix multiplication, with a thread created for each row of resultant matrix.I have checked for input they are fine.As far as I have debugged problem is in creation of the new threads.
Each thread must have been created with appropriate arguments passed to it.But this is not the case(you can check it in attachment 1 [details]).Similarly in second attachment if you give large array size , many of the elements will come 0.

Version-Release number of selected component (if applicable):

How reproducible:
compile and run both the codes.

Steps to Reproduce:
1.gcc Mat_threads3.c -lpthread
3.enter sixe -76

 similarly for first code. 
Actual results:
When the program is executed , many of the array elements are 0 for array size greater than 30 or so...

Expected results:
The parent process must have waited for all the child thread.So none of the final array element must have been zero.

Additional info:
When I uncomment  pthread_join (the one that is commented) so that a new child thread is only made after the previous one has finished, than the code works fine.But ofcourse whole concept of multithreading is violated.
Comment 1 Jakub Jelinek 2008-08-22 03:34:30 EDT
No, the problem is just that you clearly haven't understood pthread_create behavior.  You want to pass 2 numbers to the thread, but you pass always the same pointer to 2 integers to all threads.  pthread_create doesn't guarantee that by the time it returns the new thread already runs and for your needs have executed several instructions from the thread function, so sometimes you overwrite the
rc array before the last pthread_create thread (or many of them) had a chance
to fetch their values from it.
Bugzilla is not a newbie programmer help, so I won't list all possibilities how you can fix it, just one - in your case both the integers must be smaller than max (10), so you can easily encode both the integers directly into one long int,
cast it to (void *) and pass that as the argument to the thread function, then cast back to long int and decode.
Comment 2 nishant.jain10 2008-08-22 11:07:57 EDT
thanks for your time.
Actually I still think there is something not working correctly.See your explanation may be sufficient to hold for the first code.But still in second one I simply haven't passed any arguments.Moreover I have used the locks. so as to ensure only one thread runs at a time.Now I don't  understand why it returns 0 for some values.Moreover the same piece of code runs all fine on other linux distro.
but anyways thank you for your insight.I will also look further if I am wrong again :(.

Note You need to log in before you can comment on or make changes to this bug.