jekyll-theme-gaeblogx 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +9 -0
- data/_includes/algolia.html +75 -0
- data/_includes/backToTop.html +5 -0
- data/_includes/category.html +19 -0
- data/_includes/comments.html +46 -0
- data/_includes/footer.html +33 -0
- data/_includes/head.html +58 -0
- data/_includes/header.html +34 -0
- data/_includes/previousAndNext.html +13 -0
- data/_includes/sidebar-search.html +25 -0
- data/_includes/tag.html +16 -0
- data/_layouts/default.html +26 -0
- data/_layouts/demo.html +10 -0
- data/_layouts/page.html +31 -0
- data/_layouts/post.html +107 -0
- data/_sass/_backToTop.scss +49 -0
- data/_sass/_demo.scss +65 -0
- data/_sass/_footer.scss +63 -0
- data/_sass/_header.scss +174 -0
- data/_sass/_index.scss +174 -0
- data/_sass/_layout.scss +242 -0
- data/_sass/_page.scss +238 -0
- data/_sass/_post-old.scss +109 -0
- data/_sass/_post.scss +83 -0
- data/_sass/_reset.scss +119 -0
- data/_sass/_scrollbar.scss +35 -0
- data/_sass/_syntax-highlighting.scss +99 -0
- data/assets/10.jpg +0 -0
- data/assets/AWS-Introduction-ec2.png +0 -0
- data/assets/Cache-Oblivious-Algorithms-FunnelSort.jpg +0 -0
- data/assets/Condition-Variables-fig1.png +0 -0
- data/assets/Dynamic-Compilation-adaptJVM.pdf +0 -0
- data/assets/Dynamic-Compilation-dyncomp.pdf +0 -0
- data/assets/Fibonacci-Heap-Fig3.png +0 -0
- data/assets/Fibonacci-Heap-Fig5.png +0 -0
- data/assets/Fibonacci-Heap-Fig6.png +0 -0
- data/assets/Fibonacci-Heap-Fig7.png +0 -0
- data/assets/File-System-bc.jpg +0 -0
- data/assets/File-System-filetable.rich.jpg +0 -0
- data/assets/GIL-Battle.png +0 -0
- data/assets/GIL-CPU.png +0 -0
- data/assets/GIL-Check.png +0 -0
- data/assets/GIL-IO.png +0 -0
- data/assets/GIL-Measure-1.png +0 -0
- data/assets/GIL-Measure-2.png +0 -0
- data/assets/GIL-Signal.png +0 -0
- data/assets/GIL-Tick.png +0 -0
- data/assets/Garbage-Collection-Slides-gc.pdf +0 -0
- data/assets/Garbage-Collection-copying-1.png +0 -0
- data/assets/Garbage-Collection-copying-2.png +0 -0
- data/assets/Garbage-Collection-free-list.png +0 -0
- data/assets/Garbage-Collection-generation-1.png +0 -0
- data/assets/Garbage-Collection-mark-sweep.png +0 -0
- data/assets/Garbage-Collection-nursery-1.png +0 -0
- data/assets/Garbage-Collection-nursery-2.png +0 -0
- data/assets/Garbage-Collection-nursery-3.png +0 -0
- data/assets/Garbage-Collection-nursery-4.png +0 -0
- data/assets/Garbage-Collection-nursery-5.png +0 -0
- data/assets/Garbage-Collection-process.png +0 -0
- data/assets/Garbage-Collection-ref-counting.png +0 -0
- data/assets/Interpreter-Optimization-interp.pdf +0 -0
- data/assets/Memory-Management-fig1.png +0 -0
- data/assets/Memory-Management-fig2.png +0 -0
- data/assets/Memory-Management-fig3.png +0 -0
- data/assets/Memory-Management-fig4.png +0 -0
- data/assets/Memory-Management-fig5.png +0 -0
- data/assets/Memory-Management-fig6.png +0 -0
- data/assets/Memory-Management-fig7.png +0 -0
- data/assets/Memory-Management-fig8.png +0 -0
- data/assets/Multicore-GIL-1.png +0 -0
- data/assets/Multicore-GIL-2.png +0 -0
- data/assets/My-Photo.JPG +0 -0
- data/assets/Operating-System-Virtualization-ept.png +0 -0
- data/assets/Operating-System-Virtualization-guest-page.png +0 -0
- data/assets/Operating-System-Virtualization-kvm-arch.png +0 -0
- data/assets/Operating-System-Virtualization-kvm-process.png +0 -0
- data/assets/Operating-System-Virtualization-kvm-qemu.png +0 -0
- data/assets/Operating-System-Virtualization-kvm-state.png +0 -0
- data/assets/Operating-System-Virtualization-vtx.png +0 -0
- data/assets/Operating-System-Virtualization-xen-arch.png +0 -0
- data/assets/Program-Profiling-profiling.pdf +0 -0
- data/assets/Programming-Language-Virtual-Machine-vm.pdf +0 -0
- data/assets/Remote-Shell-Session-Setup-1.png +0 -0
- data/assets/Signals-1.png +0 -0
- data/assets/Signals-2.png +0 -0
- data/assets/Signals-3.png +0 -0
- data/assets/Some-Slides-about-Containers-Kubernetes.pdf +0 -0
- data/assets/Some-Slides-about-Containers-UCSB-nurmi.pdf +0 -0
- data/assets/Some-Slides-about-PaaS-CS293B_CloudPlatforms.pdf +0 -0
- data/assets/avg-1thread.c +172 -0
- data/assets/avg-manythread.c +284 -0
- data/assets/avg-nothread.c +71 -0
- data/assets/file-create1.c +75 -0
- data/assets/file-create2.c +120 -0
- data/assets/file-fd1.c +56 -0
- data/assets/file-fd2.c +25 -0
- data/assets/file-fd3.c +23 -0
- data/assets/file-read1.c +62 -0
- data/assets/file-read2.c +66 -0
- data/assets/file-seek1.c +87 -0
- data/assets/fork-1.c +35 -0
- data/assets/fork-2.c +44 -0
- data/assets/fork-3.c +60 -0
- data/assets/fork-4.c +64 -0
- data/assets/joinall-1.c +163 -0
- data/assets/joinall-2.c +162 -0
- data/assets/market-kthreads.c +465 -0
- data/assets/market-semaphore.c +504 -0
- data/assets/market1.c +478 -0
- data/assets/market2.c +490 -0
- data/assets/market3.c +503 -0
- data/assets/market4.c +509 -0
- data/assets/my-cat.c +35 -0
- data/assets/pipe-1.c +45 -0
- data/assets/pipe-2.c +80 -0
- data/assets/pipe-3.c +83 -0
- data/assets/pipe-4.c +116 -0
- data/assets/race1.c +75 -0
- data/assets/race2.c +77 -0
- data/assets/race3.c +87 -0
- data/assets/race_ABC.c +144 -0
- data/assets/search-by-algolia.svg +1 -0
- data/assets/semaphore.book.ps +8827 -0
- data/assets/sys-call1.c +20 -0
- data/assets/sys-call2.c +16 -0
- data/assets//350/265/253/347/202/2161.PNG +0 -0
- data/feed.xml +30 -0
- data/index.html +164 -0
- data/js/jekyll-search.min.js +1 -0
- data/js/lunr.min.js +2977 -0
- data/js/main.js +57 -0
- data/js/masonry.pkgd.min.js +9 -0
- data/js/pageContent.js +166 -0
- data/js/search.js +17 -0
- data/js/smooth-scroll.min.js +2 -0
- data/js/waterfall.js +214 -0
- data/page/0archives.html +83 -0
- data/page/1category.html +62 -0
- data/page/2tags.html +64 -0
- data/page/3search.html +112 -0
- data/page/4about.md +34 -0
- metadata +270 -0
data/assets/my-cat.c
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#include <unistd.h>
|
|
2
|
+
#include <stdlib.h>
|
|
3
|
+
#include <stdio.h>
|
|
4
|
+
#include <string.h>
|
|
5
|
+
#include <fcntl.h>
|
|
6
|
+
#include <string.h>
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* simple program implementing cat
|
|
10
|
+
*/
|
|
11
|
+
int main(int argc, char **argv)
|
|
12
|
+
{
|
|
13
|
+
pid_t my_id;
|
|
14
|
+
char buffer[4096];
|
|
15
|
+
|
|
16
|
+
my_id = getpid();
|
|
17
|
+
fprintf(stderr,"pid: %d -- I am my-cat and I have started\n",my_id);
|
|
18
|
+
|
|
19
|
+
memset(buffer,0,sizeof(buffer));
|
|
20
|
+
|
|
21
|
+
while(read(0,buffer,sizeof(buffer)) > 0) {
|
|
22
|
+
fprintf(stderr,"pid: %d read some data\n",getpid());
|
|
23
|
+
buffer[4095] = 0; /* safety first */
|
|
24
|
+
write(1,buffer,strlen(buffer));
|
|
25
|
+
fprintf(stderr,"pid: %d wrote some data\n",getpid());
|
|
26
|
+
memset(buffer,0,sizeof(buffer));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
fprintf(stderr,"pid: %d -- I am my-cat and I am exiting\n",my_id);
|
|
30
|
+
|
|
31
|
+
exit(0);
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
data/assets/pipe-1.c
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#include <unistd.h>
|
|
2
|
+
#include <stdlib.h>
|
|
3
|
+
#include <stdio.h>
|
|
4
|
+
#include <string.h>
|
|
5
|
+
#include <fcntl.h>
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* simple program to create and use a pipe
|
|
9
|
+
*/
|
|
10
|
+
int main(int argc, char **argv)
|
|
11
|
+
{
|
|
12
|
+
int pipe_desc[2];
|
|
13
|
+
int err;
|
|
14
|
+
char *string;
|
|
15
|
+
char read_buffer[4096];
|
|
16
|
+
|
|
17
|
+
err = pipe(pipe_desc);
|
|
18
|
+
if(err < 0) {
|
|
19
|
+
printf("error creating pipe\n");
|
|
20
|
+
exit(1);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
string = "a string";
|
|
24
|
+
|
|
25
|
+
printf("writing %s to pipe_desc[1] which is %d\n",
|
|
26
|
+
string,pipe_desc[1]);
|
|
27
|
+
|
|
28
|
+
write(pipe_desc[1],string,strlen(string));
|
|
29
|
+
|
|
30
|
+
memset(read_buffer,0,sizeof(read_buffer));
|
|
31
|
+
printf("attempting to read pipe_desc[0] which is %d\n",pipe_desc[0]);
|
|
32
|
+
read(pipe_desc[0], read_buffer, sizeof(read_buffer));
|
|
33
|
+
|
|
34
|
+
printf("read %s from pipe_desc[0]\n",read_buffer);
|
|
35
|
+
|
|
36
|
+
close(pipe_desc[0]);
|
|
37
|
+
close(pipe_desc[1]);
|
|
38
|
+
|
|
39
|
+
return(0);
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
data/assets/pipe-2.c
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#include <unistd.h>
|
|
2
|
+
#include <stdlib.h>
|
|
3
|
+
#include <stdio.h>
|
|
4
|
+
#include <string.h>
|
|
5
|
+
#include <fcntl.h>
|
|
6
|
+
#include <sys/wait.h>
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* simple program creating a pipe between two processes
|
|
10
|
+
*/
|
|
11
|
+
int main(int argc, char **argv)
|
|
12
|
+
{
|
|
13
|
+
pid_t child_id;
|
|
14
|
+
pid_t my_id;
|
|
15
|
+
int pipe_desc[2];
|
|
16
|
+
char *string;
|
|
17
|
+
char read_buffer[4096];
|
|
18
|
+
int child_status;
|
|
19
|
+
int err;
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* create the pipe
|
|
23
|
+
*/
|
|
24
|
+
err = pipe(pipe_desc);
|
|
25
|
+
if(err < 0) {
|
|
26
|
+
printf("error creating pipe\n");
|
|
27
|
+
exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/*
|
|
31
|
+
* then fork
|
|
32
|
+
*/
|
|
33
|
+
child_id = fork();
|
|
34
|
+
if(child_id != 0) {
|
|
35
|
+
/*
|
|
36
|
+
* parent will be the writer
|
|
37
|
+
* doesn't need the read end
|
|
38
|
+
*/
|
|
39
|
+
my_id = getpid();
|
|
40
|
+
close(pipe_desc[0]);
|
|
41
|
+
/*
|
|
42
|
+
* send the child a string
|
|
43
|
+
*/
|
|
44
|
+
string = "a string made by the parent\n";
|
|
45
|
+
printf("pid: %d -- writing %s to pipe_desc[1]\n",
|
|
46
|
+
(int)my_id,
|
|
47
|
+
string);
|
|
48
|
+
write(pipe_desc[1],string,strlen(string));
|
|
49
|
+
/*
|
|
50
|
+
* close the pipe to let the read end know we are
|
|
51
|
+
* done
|
|
52
|
+
*/
|
|
53
|
+
close(pipe_desc[1]);
|
|
54
|
+
/*
|
|
55
|
+
* wait for the child to exit
|
|
56
|
+
*/
|
|
57
|
+
wait(&child_status);
|
|
58
|
+
} else {
|
|
59
|
+
/*
|
|
60
|
+
* child reads the read end
|
|
61
|
+
*/
|
|
62
|
+
my_id = getpid();
|
|
63
|
+
/*
|
|
64
|
+
* doesn't need the write end
|
|
65
|
+
*/
|
|
66
|
+
close(pipe_desc[1]);
|
|
67
|
+
memset(read_buffer,0,sizeof(read_buffer));
|
|
68
|
+
read(pipe_desc[0],read_buffer,sizeof(read_buffer));
|
|
69
|
+
printf("pid: %d -- received %s from parent\n",
|
|
70
|
+
(int)my_id,
|
|
71
|
+
read_buffer);
|
|
72
|
+
close(pipe_desc[0]);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
printf("pid: %d -- I am exiting\n",my_id);
|
|
76
|
+
exit(0);
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
data/assets/pipe-3.c
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#include <unistd.h>
|
|
2
|
+
#include <stdlib.h>
|
|
3
|
+
#include <stdio.h>
|
|
4
|
+
#include <string.h>
|
|
5
|
+
#include <fcntl.h>
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* simple program creating a pipe between two processes
|
|
9
|
+
*/
|
|
10
|
+
int main(int argc, char **argv)
|
|
11
|
+
{
|
|
12
|
+
pid_t child_id;
|
|
13
|
+
pid_t my_id;
|
|
14
|
+
int pipe_desc[2];
|
|
15
|
+
char *string;
|
|
16
|
+
char read_buffer[4096];
|
|
17
|
+
int err;
|
|
18
|
+
|
|
19
|
+
/*
|
|
20
|
+
* create the pipe
|
|
21
|
+
*/
|
|
22
|
+
err = pipe(pipe_desc);
|
|
23
|
+
if(err < 0) {
|
|
24
|
+
printf("error creating pipe\n");
|
|
25
|
+
exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/*
|
|
29
|
+
* then fork
|
|
30
|
+
*/
|
|
31
|
+
child_id = fork();
|
|
32
|
+
if(child_id != 0) {
|
|
33
|
+
/*
|
|
34
|
+
* parent will be the writer
|
|
35
|
+
* doesn't need the read end
|
|
36
|
+
*/
|
|
37
|
+
my_id = getpid();
|
|
38
|
+
close(pipe_desc[0]);
|
|
39
|
+
/*
|
|
40
|
+
* send the child a string
|
|
41
|
+
*/
|
|
42
|
+
string = "a string made by the parent\n";
|
|
43
|
+
printf("pid: %d -- writing %s to pipe_desc[1]\n",
|
|
44
|
+
(int)my_id,
|
|
45
|
+
string);
|
|
46
|
+
write(pipe_desc[1],string,strlen(string));
|
|
47
|
+
/*
|
|
48
|
+
* and another string
|
|
49
|
+
*/
|
|
50
|
+
string = "and another string";
|
|
51
|
+
printf("pid: %d -- writing %s to pipe_desc[1]\n",
|
|
52
|
+
(int)my_id,
|
|
53
|
+
string);
|
|
54
|
+
write(pipe_desc[1],string,strlen(string));
|
|
55
|
+
/*
|
|
56
|
+
* close the pipe to let the read end know we are
|
|
57
|
+
* done
|
|
58
|
+
*/
|
|
59
|
+
} else {
|
|
60
|
+
/*
|
|
61
|
+
* child will read until pipe closes
|
|
62
|
+
* close the write end
|
|
63
|
+
*/
|
|
64
|
+
my_id = getpid();
|
|
65
|
+
close(pipe_desc[1]);
|
|
66
|
+
memset(read_buffer,0,sizeof(read_buffer));
|
|
67
|
+
while(read(pipe_desc[0],read_buffer,sizeof(read_buffer))) {
|
|
68
|
+
printf("pid: %d -- received %s from parent\n",
|
|
69
|
+
(int)my_id,
|
|
70
|
+
read_buffer);
|
|
71
|
+
memset(read_buffer,0,sizeof(read_buffer));
|
|
72
|
+
}
|
|
73
|
+
printf("pid: %d -- child detects write end closed\n",
|
|
74
|
+
(int)my_id);
|
|
75
|
+
close(pipe_desc[0]);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
printf("pid: %d -- I am exiting\n",my_id);
|
|
79
|
+
exit(0);
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
data/assets/pipe-4.c
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#include <unistd.h>
|
|
2
|
+
#include <stdlib.h>
|
|
3
|
+
#include <stdio.h>
|
|
4
|
+
#include <string.h>
|
|
5
|
+
#include <fcntl.h>
|
|
6
|
+
#include <sys/wait.h>
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* simple program creating a pipe between a set of processes
|
|
10
|
+
* that read and write stdin and stdout
|
|
11
|
+
* first child get stdin of parent
|
|
12
|
+
* last child gets stdout of parent
|
|
13
|
+
*/
|
|
14
|
+
int main(int argc, char **argv, char **envp)
|
|
15
|
+
{
|
|
16
|
+
pid_t child_id;
|
|
17
|
+
int child_status;
|
|
18
|
+
int pipe_desc[2];
|
|
19
|
+
char read_buffer[4096];
|
|
20
|
+
int err;
|
|
21
|
+
char file_name[4096];
|
|
22
|
+
int proc_count;
|
|
23
|
+
int i;
|
|
24
|
+
int last_stdout;
|
|
25
|
+
|
|
26
|
+
if(argc < 3) {
|
|
27
|
+
printf("usage: pipe-4 executable-file number-of-procs\n");
|
|
28
|
+
exit(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/*
|
|
32
|
+
* get the arguments
|
|
33
|
+
*/
|
|
34
|
+
memset(file_name,0,sizeof(file_name));
|
|
35
|
+
strncpy(file_name,argv[1],sizeof(file_name));
|
|
36
|
+
proc_count = atoi(argv[2]);
|
|
37
|
+
|
|
38
|
+
/*
|
|
39
|
+
* save the parent stdout for the last child
|
|
40
|
+
*/
|
|
41
|
+
last_stdout = dup(1);
|
|
42
|
+
|
|
43
|
+
/*
|
|
44
|
+
* create pipes, fork and exec the processes
|
|
45
|
+
*/
|
|
46
|
+
for(i=0; i < proc_count; i++) {
|
|
47
|
+
/*
|
|
48
|
+
* create the pipe
|
|
49
|
+
*/
|
|
50
|
+
err = pipe(pipe_desc);
|
|
51
|
+
if(err < 0) {
|
|
52
|
+
printf("error creating pipe\n");
|
|
53
|
+
exit(1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/*
|
|
57
|
+
* then fork
|
|
58
|
+
*/
|
|
59
|
+
child_id = fork();
|
|
60
|
+
if(child_id == 0) {
|
|
61
|
+
/*
|
|
62
|
+
* child closes standard out
|
|
63
|
+
*/
|
|
64
|
+
close(1);
|
|
65
|
+
/*
|
|
66
|
+
* child dups the write end of the pipe
|
|
67
|
+
* if it is not the last child, otherwise
|
|
68
|
+
* it dups the last_stdout it got from the parent
|
|
69
|
+
* the closed stdout will be chosen as the
|
|
70
|
+
* target
|
|
71
|
+
*/
|
|
72
|
+
if(i < (proc_count - 1)) {
|
|
73
|
+
dup2(pipe_desc[1],1);
|
|
74
|
+
} else {
|
|
75
|
+
dup2(last_stdout,1);
|
|
76
|
+
close(pipe_desc[1]);
|
|
77
|
+
}
|
|
78
|
+
/*
|
|
79
|
+
* child runs the program
|
|
80
|
+
*/
|
|
81
|
+
err = execve(file_name,&argv[1],envp);
|
|
82
|
+
printf("parent error: %s didn't exec\n",
|
|
83
|
+
file_name);
|
|
84
|
+
exit(1);
|
|
85
|
+
} else {
|
|
86
|
+
/*
|
|
87
|
+
* parent closes standard in
|
|
88
|
+
*/
|
|
89
|
+
close(0);
|
|
90
|
+
/*
|
|
91
|
+
* parent dups the read end of the pipe for the
|
|
92
|
+
* next child
|
|
93
|
+
*/
|
|
94
|
+
if(i < (proc_count - 1)) {
|
|
95
|
+
dup2(pipe_desc[0],0);
|
|
96
|
+
}
|
|
97
|
+
close(pipe_desc[0]);
|
|
98
|
+
close(pipe_desc[1]);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
close(1);
|
|
103
|
+
dup2(last_stdout,1);
|
|
104
|
+
/*
|
|
105
|
+
* parent now waits for the children to exit
|
|
106
|
+
*/
|
|
107
|
+
for(i=0; i < proc_count; i++) {
|
|
108
|
+
child_id = wait(&child_status);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
exit(0);
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
data/assets/race1.c
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* CS170: race1.c
|
|
3
|
+
* adapted from code by Jim Plank
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#include <unistd.h>
|
|
7
|
+
#include <stdlib.h>
|
|
8
|
+
#include <stdio.h>
|
|
9
|
+
#include <pthread.h>
|
|
10
|
+
|
|
11
|
+
typedef struct {
|
|
12
|
+
int id;
|
|
13
|
+
int size;
|
|
14
|
+
int iterations;
|
|
15
|
+
char *s;
|
|
16
|
+
} Thread_struct;
|
|
17
|
+
|
|
18
|
+
void *infloop(void *x)
|
|
19
|
+
{
|
|
20
|
+
int i, j;
|
|
21
|
+
Thread_struct *t;
|
|
22
|
+
|
|
23
|
+
t = (Thread_struct *) x;
|
|
24
|
+
|
|
25
|
+
for (i = 0; i < t->iterations; i++)
|
|
26
|
+
{
|
|
27
|
+
for (j = 0; j < t->size-1; j++)
|
|
28
|
+
{
|
|
29
|
+
t->s[j] = 'A'+t->id;
|
|
30
|
+
}
|
|
31
|
+
t->s[j] = '\0';
|
|
32
|
+
printf("Thread %d: %s\n", t->id, t->s);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
pthread_exit(NULL);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
int
|
|
39
|
+
main(int argc, char **argv)
|
|
40
|
+
{
|
|
41
|
+
pthread_t *tid;
|
|
42
|
+
Thread_struct *t;
|
|
43
|
+
void *retval;
|
|
44
|
+
int nthreads, size, iterations, i;
|
|
45
|
+
char *s;
|
|
46
|
+
|
|
47
|
+
if (argc != 4)
|
|
48
|
+
{
|
|
49
|
+
fprintf(stderr, "usage: race nthreads stringsize iterations\n");
|
|
50
|
+
exit(1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
nthreads = atoi(argv[1]);
|
|
54
|
+
size = atoi(argv[2])+1;
|
|
55
|
+
iterations = atoi(argv[3]);
|
|
56
|
+
|
|
57
|
+
tid = (pthread_t *) malloc(sizeof(pthread_t) * nthreads);
|
|
58
|
+
t = (Thread_struct *) malloc(sizeof(Thread_struct) * nthreads);
|
|
59
|
+
s = (char *) malloc(sizeof(char) * size);
|
|
60
|
+
|
|
61
|
+
for (i = 0; i < nthreads; i++)
|
|
62
|
+
{
|
|
63
|
+
t[i].id = i;
|
|
64
|
+
t[i].size = size;
|
|
65
|
+
t[i].iterations = iterations;
|
|
66
|
+
t[i].s = s;
|
|
67
|
+
pthread_create(&(tid[i]), NULL, infloop, &(t[i]));
|
|
68
|
+
}
|
|
69
|
+
for (i = 0; i < nthreads; i++)
|
|
70
|
+
{
|
|
71
|
+
pthread_join(tid[i], &retval);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return(0);
|
|
75
|
+
}
|
data/assets/race2.c
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* CS170: race2.c
|
|
3
|
+
* adapted from code by Jim Plank
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#include <unistd.h>
|
|
7
|
+
#include <stdlib.h>
|
|
8
|
+
#include <stdio.h>
|
|
9
|
+
#include <pthread.h>
|
|
10
|
+
|
|
11
|
+
typedef struct {
|
|
12
|
+
int id;
|
|
13
|
+
int size;
|
|
14
|
+
int iterations;
|
|
15
|
+
char *s;
|
|
16
|
+
} Thread_struct;
|
|
17
|
+
|
|
18
|
+
void *infloop(void *x)
|
|
19
|
+
{
|
|
20
|
+
int i, j, k;
|
|
21
|
+
Thread_struct *t;
|
|
22
|
+
|
|
23
|
+
t = (Thread_struct *) x;
|
|
24
|
+
|
|
25
|
+
for (i = 0; i < t->iterations; i++)
|
|
26
|
+
{
|
|
27
|
+
for (j = 0; j < t->size-1; j++)
|
|
28
|
+
{
|
|
29
|
+
t->s[j] = 'A'+t->id;
|
|
30
|
+
/* needed because machines are so darn fast */
|
|
31
|
+
for(k=0; k < 80000; k++);
|
|
32
|
+
}
|
|
33
|
+
t->s[j] = '\0';
|
|
34
|
+
printf("Thread %d: %s\n", t->id, t->s);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
pthread_exit(NULL);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
int
|
|
41
|
+
main(int argc, char **argv)
|
|
42
|
+
{
|
|
43
|
+
pthread_t *tid;
|
|
44
|
+
Thread_struct *t;
|
|
45
|
+
void *retval;
|
|
46
|
+
int nthreads, size, iterations, i;
|
|
47
|
+
char *s;
|
|
48
|
+
|
|
49
|
+
if (argc != 4)
|
|
50
|
+
{
|
|
51
|
+
fprintf(stderr, "usage: race nthreads stringsize iterations\n");
|
|
52
|
+
exit(1);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
nthreads = atoi(argv[1]);
|
|
56
|
+
size = atoi(argv[2])+1;
|
|
57
|
+
iterations = atoi(argv[3]);
|
|
58
|
+
|
|
59
|
+
tid = (pthread_t *) malloc(sizeof(pthread_t) * nthreads);
|
|
60
|
+
t = (Thread_struct *) malloc(sizeof(Thread_struct) * nthreads);
|
|
61
|
+
s = (char *) malloc(sizeof(char) * size);
|
|
62
|
+
|
|
63
|
+
for (i = 0; i < nthreads; i++)
|
|
64
|
+
{
|
|
65
|
+
t[i].id = i;
|
|
66
|
+
t[i].size = size;
|
|
67
|
+
t[i].iterations = iterations;
|
|
68
|
+
t[i].s = s;
|
|
69
|
+
pthread_create(&(tid[i]), NULL, infloop, &(t[i]));
|
|
70
|
+
}
|
|
71
|
+
for (i = 0; i < nthreads; i++)
|
|
72
|
+
{
|
|
73
|
+
pthread_join(tid[i], &retval);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return(0);
|
|
77
|
+
}
|