Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab2 TA Notes. Set up for Visual C++ New Workspace Win32 Console Application – This runs from a command line Chose Blank Project Add your.C file Build.

Similar presentations


Presentation on theme: "Lab2 TA Notes. Set up for Visual C++ New Workspace Win32 Console Application – This runs from a command line Chose Blank Project Add your.C file Build."— Presentation transcript:

1 Lab2 TA Notes

2 Set up for Visual C++ New Workspace Win32 Console Application – This runs from a command line Chose Blank Project Add your.C file Build project

3 Visual C++ Settings Change MLD to MTD under Project Options

4 Visual C++ Settings Change MLD to MTD under Project Options How to do this? Set category: code generation, and Use run-time library: Debug Multithreaded

5 Visual C++ Settings Add under Object/library modules: libcmtd.lib and

6 Visual C++ Settings If you add under Object/library /Nodefaultlib:library with substituting word library to the real name of the library, say abc.lib this library will be ignored in linking. Do not forget slash /. The checkbox “Ignore all default libraries” will do the same for all libraries. In typical cases you have no conflicts in libraries and do not need to ignore any libraries. /nodefaultlib:library

7 Part A Use int main(int argc, char *argv[]) – This will allow you to read in the correct parameters for the program. Error check the parameters sent to the program, use fprintf(stderr, message) to inform the user of an error. If parameters are correct use: – fopen(argv[1], “r”)

8 Part A continued Use fgets(cmdLine, lineLen, fid) to read in each line and create the process requested. Use CreateProcess( ) to create each process requested. If process is not created give error message. Close handles for all threads and processes.

9 Part B Setup Visual C++ project same as Part A. Read in parameters and error check as in Part A. Use atoi(argv[1]) to set number of threads to run. Use atoi(argv[2]) to set the amount of time to run.

10 Part B Continued Calculate the stop time. Show user the starting time. Set variables for stop time. Use a loop to create and run the appropriate number of threads. Use printf( ) to show that each thread is running.

11 Part B Continued Use while(runFlag) to pole system time to know when to stop threads. Use printf( ) to show when the threads are stopping and also to show they have terminated. Use the function out of the book (p.88) Threadwork to create work for each thread to do.


Download ppt "Lab2 TA Notes. Set up for Visual C++ New Workspace Win32 Console Application – This runs from a command line Chose Blank Project Add your.C file Build."

Similar presentations


Ads by Google