News for hackers. Stuff that matters.
Re:Make your program slower with threads by fche on Sunday December 07, 2014 @09:51AM (#8712314)
The author's multithreaded random_r version has the benefit of performance, but has the problem of, well, brokenness. Without locking the internal state of random_r(), it will be corrupted, and the results won't be meaningful.
Re:Make your program slower with threads by mjb on Sunday December 07, 2014 @10:23AM (#8712397)
Can you explain more? My understanding (which seems to be backed up by the implementation) is that I can call initstate_r in each thread to initialize thread-local state, then call random_r without synchronization from each thread as long as I used that thread's thread-local state.

random_r's internal state is all, from what I can see of the implementation, entirely passed in by the caller. Implementation here: https://sourceware.org/git/?p=glibc.git;a=blob;f=stdlib/rand...

Re:Make your program slower with threads by ScottBurson on Sunday December 07, 2014 @02:10PM (#8713193)
You are correct, and 'fche is mistaken. Each 'random_data' object is accessed only from a single thread.
Re:Make your program slower with threads by barrkel on Sunday December 07, 2014 @10:31AM (#8712429)
random_r doesn't have internal state.