1 / 15

CS 241 Section (03/15/2012)

CS 241 Section (03/15/2012). MP6. This MP is simple: Create a ‘make’ utility. MP6. This MP is simple: Create a ‘make’ utility. What does ‘make’ do? Reads a ‘makefile’ Determines the tasks that are available to run based on dependency rules Run until all tasks are finished. MP6.

eroark
Télécharger la présentation

CS 241 Section (03/15/2012)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 241 Section(03/15/2012)

  2. MP6 • This MP is simple: • Create a ‘make’ utility.

  3. MP6 • This MP is simple: • Create a ‘make’ utility. • What does ‘make’ do? • Reads a ‘makefile’ • Determines the tasks that are available to run based on dependency rules • Run until all tasks are finished

  4. MP6 job1: job2 job3    commandtoberun withargs    commandtoberun2 withargs job2:    othercommand job3:    finalcommand

  5. MP6 target job1: job2 job3    commandtoberun withargs    commandtoberun2 withargs job2:    othercommand job3:    finalcommand

  6. MP6 dependencies job1: job2 job3    commandtoberun withargs    commandtoberun2 withargs job2:    othercommand job3:    finalcommand

  7. MP6 job1: job2 job3    commandtoberun withargs    commandtoberun2 withargs job2:    othercommand job3:    finalcommand commands

  8. MP6 • We can show this graphically: …job1 depends on job2 and job3 being done. job2 job1 job3

  9. MP6 • In MP6, you will specify (with the –j # option) how many worker threads should run. • “-j 1”: Only one worker thread • “-j 2”: Two worker threads • “-j 100”: One hundred worker threads • Use getopt() to handle command-line options

  10. MP6 • If the makefile is ran with –j 2, then: [thread a]: job2 runs [thread b]: job3 runs [thread b]: job3 finishes [thread b]: idle, job1 not ready[thread a]: job2 finishes [thread a OR b]: job1 runs [thread a OR b]: job1 finishes [thread a AND b]: exit, all jobs done [main thread]: join threads, exit

  11. MP6 • We provide you some tools you can use, if you’d like: • queue.c: A queue data structure • parser.c: A parser for makefiles • parser_parse_makefile(…) takes function pointers as arguments that will be called when it reaches a key, dependency, or command.

  12. MP6 Parser Callbacks parsed_new_key(key=job1) parsed_dependency(key=job1, dep=job2) parsed_dependency(key=job1, dep=job3) parsed_command(key=job1, command=...) parsed_command(key=job1, command=...) parsed_new_key(key=job2) parsed_command(key=job2, command=...) parsed_new_key(key=job3) parsed_command(key=job3, command=...)

  13. MP6 • Some useful functions: • pthread_create(), pthread_join() • sem_init(), sem_wait(), sem_post(), sem_destroy() • system() • Does fork(), exec(), and wait() for you in one command! • Remember to check return values! You may find some weird things going on with semaphores if you don’t… Good luck!

  14. MP6 • Run a rule only if any dependency has a modification time more recent than the target. • You can get the modification time of a file using stat()

  15. Coding Examples • This week:ds/ds6/

More Related