|
@@ -5,10 +5,9 @@
|
|
|
#include "example.h"
|
|
|
#include "example2.h"
|
|
|
|
|
|
-int
|
|
|
-example1 (int argc, char** argv)
|
|
|
+int example1(int argc, char **argv)
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
int i;
|
|
|
pthread_t id[argc];
|
|
|
pthread_attr_t attr;
|
|
@@ -19,20 +18,21 @@ example1 (int argc, char** argv)
|
|
|
return (1);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
pthread_attr_init(&attr);
|
|
|
- for (i=1; i<argc;i++){
|
|
|
- d[i-1].limit = atoi(argv[i]);
|
|
|
- d[i-1].answer = 0;
|
|
|
- pthread_create(&id[i-1], &attr, runner1, &d[i-1]);
|
|
|
+ for (i = 1; i < argc; i++) {
|
|
|
+ d[i - 1].limit = atoi(argv[i]);
|
|
|
+ d[i - 1].answer = 0;
|
|
|
+ pthread_create(&id[i - 1], &attr, runner1, &d[i - 1]);
|
|
|
}
|
|
|
|
|
|
- for (i=0;i<argc-1;i++){
|
|
|
-
|
|
|
+ for (i = 0; i < argc - 1; i++) {
|
|
|
+
|
|
|
pthread_join(id[i], NULL);
|
|
|
- printf("\n\nFib of limit: %d is %d", d[i].limit, d[i].answer);
|
|
|
-
|
|
|
+ printf("\n\nFib of limit: %d is %d", d[i].limit,
|
|
|
+ d[i].answer);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
return (0);
|
|
@@ -43,26 +43,27 @@ example1 (int argc, char** argv)
|
|
|
int example2(int argc, char **argv)
|
|
|
{
|
|
|
|
|
|
- pthread_t id[2];
|
|
|
- pthread_attr_t attr;
|
|
|
- buffer buf;
|
|
|
+ pthread_t id[2];
|
|
|
+ pthread_attr_t attr;
|
|
|
+ buffer buf;
|
|
|
|
|
|
- init_buffer(&buf);
|
|
|
+ init_buffer(&buf);
|
|
|
|
|
|
- pthread_attr_init(&attr);
|
|
|
- pthread_create(&id[0], &attr, produce, &buf);
|
|
|
- pthread_create(&id[1], &attr, consume, &buf);
|
|
|
+ pthread_attr_init(&attr);
|
|
|
+ pthread_create(&id[0], &attr, produce, &buf);
|
|
|
+ pthread_create(&id[1], &attr, consume, &buf);
|
|
|
|
|
|
- pthread_join(id[0], NULL);
|
|
|
- pthread_join(id[1], NULL);
|
|
|
+ pthread_join(id[0], NULL);
|
|
|
+ pthread_join(id[1], NULL);
|
|
|
|
|
|
- sem_destroy(&buf.empty);
|
|
|
- pthread_mutex_destroy(&buf.mutex);
|
|
|
+ sem_destroy(&buf.empty);
|
|
|
+ pthread_mutex_destroy(&buf.mutex);
|
|
|
|
|
|
- printf("\nProgram finished");
|
|
|
- return (EXIT_SUCCESS);
|
|
|
+ printf("\nProgram finished");
|
|
|
+ return (EXIT_SUCCESS);
|
|
|
}
|
|
|
|
|
|
-int main(int argc, char **argv){
|
|
|
- example2(argc, argv);
|
|
|
-}
|
|
|
+int main(int argc, char **argv)
|
|
|
+{
|
|
|
+ example2(argc, argv);
|
|
|
+}
|