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: Which ones? code/threads/hellobug.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #include "csapp.h" void *thread(void *vargp); int main() { pthread_t tid; Pthread_create(&tid, NULL, thread, NULL); exit(0); } /* thread routine */ void *thread(void *vargp) { Sleep(1); printf("Hello, world!\n"); return NULL; } code/threads/hellobug.c Figure 11.6: Buggy program for Problem 11.1. 570 CHAPTER 11. CONCURRENT PROGRAMMING WITH THREADS 11.3 Shared Variables in Threaded Programs From a programmer’s perspective, one of the attractive aspects of threads is the ease with which multiple threads can share the same program variables. However, in order to use threads correctly, we must have a clear understanding of what we mean by sharing and how it works. There are some basic questions to work through in order to understand whether a variable in a C program is shared or not: (1) What is the underlying memory model for threads? (2) Given this model, how are instances of the variable mapped t...
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