Commit e0608595 authored by Son Pham's avatar Son Pham

Lab 5 with answers.txt

parent eeb02fec
# Name: Son Pham
# Class: CSCI 315
# Prof: Luiz Felipe Perrone
# answers.txt - Lab 5
3.
rand(3) is not thread-safe since it use a hidden state in the memory to produce the (pseudo) random integer. Since this area of memory can be accessed by any threads, it is not thread-safe. Two threads, due to overlap, can get the same state and produce the same random integer, which is not what we want.
rand_r(3) fixed this issue because the seed is now stored in the stack with an (unsigned int*) pointer, which is only locally accessible to the thread. The state is now independently modified by each thread and the operation on one thread should not affect each other. This clearly makes rand_r thread-safe.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment