4.9.   169

 4.7       "-
",    4.5  4.6.

//  4.7

1 #include <sys/stat.h>

2 #include <fstream>

3 #include <queue>

4 #include <algorithm>

5 #include <pthread.h>

6 #include <iostream>

7 ttinclude <set>

8

9 pthread_mutex_t QueueMutex = PTHREAD_MUTEX_INITIALIZER;

10 pthread_mutex_t CountMutex = PTHREAD_MUTEX_INITIALIZER;

11

12 int FileCount = 0;

13 int FoundCount = 0;

14

15 int keySearch(void);

16 queue<string> TextFiles;

17 set <string,less<string> >KeyWords;

18 set <string,less<string> >SearchWords;

19 ifstream Infile;

20 ofstream Outfile;

21 if stream Keyfile;

22 string KeywordFile;

23 string OutFilename;

24 pthread_t Threadi;

2 5 pthread_t Thread2 ;

26

27 void depthFirstTraversal(const char *CurrentDir);

28 int isDirectory(string FileName);

29 int isRegular(string FileName);

30

31 int main(int argc, char *argv[])

32 {

33   i?(argc != 4){

34      cerr  "  ."  endl;

35      exit (1);

36   }

37

38   Out file.open(argv[3],ios::app||ios::ate) ;

39   Keyfile.open(argv[2]);

40   pthread_create(&Threadl,NULL,task,argv[l]) ;

41   pthread_create(&Thread2,NULL,keySearch,argv[l]) ;

42   pthread_join(Threadi,NULL);

43   pthread_join(Thread2,NULL);

44   pthread_mutex_destroy(&CountMutex) ;

45   pthread_mutex_destroy(&QueueMutex) ;

46

47   cout  argv[l]  "  "  FoundCount

 "     ."  endl;

48   return(0) ;

49 }