In general routers can be used to build internets

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: unprotected global counter variable. This class of thread-unsafe function is relatively easy to make thread-safe: protect the shared variables with the appropriate synchronization operations (e.g., È and Î functions or Pthreads lock and unlock functions). An advantage is that it does not require any changes in the calling program. A disadvantage is that the synchronization operations will slow down the function. 2. Relying on state across multiple function invocations. A pseudo-random number generator is a good example of this class of thread-unsafe function. Consider the rand package from [37]: code/threads/rand.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 unsigned int next = 1; /* rand - return pseudo-random integer on 0..32767 */ int rand(void) { next = next*1103515245 + 12345; return (unsigned int)(next/65536) % 32768; } /* srand - set seed for rand() */ void srand(unsigned int seed) { next = seed; } code/threads/rand.c The rand function is thread-unsafe because the result of the current invocation dep...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online