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.
Files changed (144) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +9 -0
  4. data/_includes/algolia.html +75 -0
  5. data/_includes/backToTop.html +5 -0
  6. data/_includes/category.html +19 -0
  7. data/_includes/comments.html +46 -0
  8. data/_includes/footer.html +33 -0
  9. data/_includes/head.html +58 -0
  10. data/_includes/header.html +34 -0
  11. data/_includes/previousAndNext.html +13 -0
  12. data/_includes/sidebar-search.html +25 -0
  13. data/_includes/tag.html +16 -0
  14. data/_layouts/default.html +26 -0
  15. data/_layouts/demo.html +10 -0
  16. data/_layouts/page.html +31 -0
  17. data/_layouts/post.html +107 -0
  18. data/_sass/_backToTop.scss +49 -0
  19. data/_sass/_demo.scss +65 -0
  20. data/_sass/_footer.scss +63 -0
  21. data/_sass/_header.scss +174 -0
  22. data/_sass/_index.scss +174 -0
  23. data/_sass/_layout.scss +242 -0
  24. data/_sass/_page.scss +238 -0
  25. data/_sass/_post-old.scss +109 -0
  26. data/_sass/_post.scss +83 -0
  27. data/_sass/_reset.scss +119 -0
  28. data/_sass/_scrollbar.scss +35 -0
  29. data/_sass/_syntax-highlighting.scss +99 -0
  30. data/assets/10.jpg +0 -0
  31. data/assets/AWS-Introduction-ec2.png +0 -0
  32. data/assets/Cache-Oblivious-Algorithms-FunnelSort.jpg +0 -0
  33. data/assets/Condition-Variables-fig1.png +0 -0
  34. data/assets/Dynamic-Compilation-adaptJVM.pdf +0 -0
  35. data/assets/Dynamic-Compilation-dyncomp.pdf +0 -0
  36. data/assets/Fibonacci-Heap-Fig3.png +0 -0
  37. data/assets/Fibonacci-Heap-Fig5.png +0 -0
  38. data/assets/Fibonacci-Heap-Fig6.png +0 -0
  39. data/assets/Fibonacci-Heap-Fig7.png +0 -0
  40. data/assets/File-System-bc.jpg +0 -0
  41. data/assets/File-System-filetable.rich.jpg +0 -0
  42. data/assets/GIL-Battle.png +0 -0
  43. data/assets/GIL-CPU.png +0 -0
  44. data/assets/GIL-Check.png +0 -0
  45. data/assets/GIL-IO.png +0 -0
  46. data/assets/GIL-Measure-1.png +0 -0
  47. data/assets/GIL-Measure-2.png +0 -0
  48. data/assets/GIL-Signal.png +0 -0
  49. data/assets/GIL-Tick.png +0 -0
  50. data/assets/Garbage-Collection-Slides-gc.pdf +0 -0
  51. data/assets/Garbage-Collection-copying-1.png +0 -0
  52. data/assets/Garbage-Collection-copying-2.png +0 -0
  53. data/assets/Garbage-Collection-free-list.png +0 -0
  54. data/assets/Garbage-Collection-generation-1.png +0 -0
  55. data/assets/Garbage-Collection-mark-sweep.png +0 -0
  56. data/assets/Garbage-Collection-nursery-1.png +0 -0
  57. data/assets/Garbage-Collection-nursery-2.png +0 -0
  58. data/assets/Garbage-Collection-nursery-3.png +0 -0
  59. data/assets/Garbage-Collection-nursery-4.png +0 -0
  60. data/assets/Garbage-Collection-nursery-5.png +0 -0
  61. data/assets/Garbage-Collection-process.png +0 -0
  62. data/assets/Garbage-Collection-ref-counting.png +0 -0
  63. data/assets/Interpreter-Optimization-interp.pdf +0 -0
  64. data/assets/Memory-Management-fig1.png +0 -0
  65. data/assets/Memory-Management-fig2.png +0 -0
  66. data/assets/Memory-Management-fig3.png +0 -0
  67. data/assets/Memory-Management-fig4.png +0 -0
  68. data/assets/Memory-Management-fig5.png +0 -0
  69. data/assets/Memory-Management-fig6.png +0 -0
  70. data/assets/Memory-Management-fig7.png +0 -0
  71. data/assets/Memory-Management-fig8.png +0 -0
  72. data/assets/Multicore-GIL-1.png +0 -0
  73. data/assets/Multicore-GIL-2.png +0 -0
  74. data/assets/My-Photo.JPG +0 -0
  75. data/assets/Operating-System-Virtualization-ept.png +0 -0
  76. data/assets/Operating-System-Virtualization-guest-page.png +0 -0
  77. data/assets/Operating-System-Virtualization-kvm-arch.png +0 -0
  78. data/assets/Operating-System-Virtualization-kvm-process.png +0 -0
  79. data/assets/Operating-System-Virtualization-kvm-qemu.png +0 -0
  80. data/assets/Operating-System-Virtualization-kvm-state.png +0 -0
  81. data/assets/Operating-System-Virtualization-vtx.png +0 -0
  82. data/assets/Operating-System-Virtualization-xen-arch.png +0 -0
  83. data/assets/Program-Profiling-profiling.pdf +0 -0
  84. data/assets/Programming-Language-Virtual-Machine-vm.pdf +0 -0
  85. data/assets/Remote-Shell-Session-Setup-1.png +0 -0
  86. data/assets/Signals-1.png +0 -0
  87. data/assets/Signals-2.png +0 -0
  88. data/assets/Signals-3.png +0 -0
  89. data/assets/Some-Slides-about-Containers-Kubernetes.pdf +0 -0
  90. data/assets/Some-Slides-about-Containers-UCSB-nurmi.pdf +0 -0
  91. data/assets/Some-Slides-about-PaaS-CS293B_CloudPlatforms.pdf +0 -0
  92. data/assets/avg-1thread.c +172 -0
  93. data/assets/avg-manythread.c +284 -0
  94. data/assets/avg-nothread.c +71 -0
  95. data/assets/file-create1.c +75 -0
  96. data/assets/file-create2.c +120 -0
  97. data/assets/file-fd1.c +56 -0
  98. data/assets/file-fd2.c +25 -0
  99. data/assets/file-fd3.c +23 -0
  100. data/assets/file-read1.c +62 -0
  101. data/assets/file-read2.c +66 -0
  102. data/assets/file-seek1.c +87 -0
  103. data/assets/fork-1.c +35 -0
  104. data/assets/fork-2.c +44 -0
  105. data/assets/fork-3.c +60 -0
  106. data/assets/fork-4.c +64 -0
  107. data/assets/joinall-1.c +163 -0
  108. data/assets/joinall-2.c +162 -0
  109. data/assets/market-kthreads.c +465 -0
  110. data/assets/market-semaphore.c +504 -0
  111. data/assets/market1.c +478 -0
  112. data/assets/market2.c +490 -0
  113. data/assets/market3.c +503 -0
  114. data/assets/market4.c +509 -0
  115. data/assets/my-cat.c +35 -0
  116. data/assets/pipe-1.c +45 -0
  117. data/assets/pipe-2.c +80 -0
  118. data/assets/pipe-3.c +83 -0
  119. data/assets/pipe-4.c +116 -0
  120. data/assets/race1.c +75 -0
  121. data/assets/race2.c +77 -0
  122. data/assets/race3.c +87 -0
  123. data/assets/race_ABC.c +144 -0
  124. data/assets/search-by-algolia.svg +1 -0
  125. data/assets/semaphore.book.ps +8827 -0
  126. data/assets/sys-call1.c +20 -0
  127. data/assets/sys-call2.c +16 -0
  128. data/assets//350/265/253/347/202/2161.PNG +0 -0
  129. data/feed.xml +30 -0
  130. data/index.html +164 -0
  131. data/js/jekyll-search.min.js +1 -0
  132. data/js/lunr.min.js +2977 -0
  133. data/js/main.js +57 -0
  134. data/js/masonry.pkgd.min.js +9 -0
  135. data/js/pageContent.js +166 -0
  136. data/js/search.js +17 -0
  137. data/js/smooth-scroll.min.js +2 -0
  138. data/js/waterfall.js +214 -0
  139. data/page/0archives.html +83 -0
  140. data/page/1category.html +62 -0
  141. data/page/2tags.html +64 -0
  142. data/page/3search.html +112 -0
  143. data/page/4about.md +34 -0
  144. metadata +270 -0
data/assets/market3.c ADDED
@@ -0,0 +1,503 @@
1
+ /*
2
+ * cs170 -- Rich wolski
3
+ * producer-consumer example
4
+ * uses condition variables for fule/empty conditions
5
+ * uses condition variable to fulfill order
6
+ */
7
+ #include <unistd.h>
8
+ #include <stdlib.h>
9
+ #include <stdio.h>
10
+ #include <pthread.h>
11
+ #include <string.h>
12
+
13
+ #include "c-timer.h"
14
+
15
+ #define RAND() (drand48())
16
+
17
+ struct order
18
+ {
19
+ int stock_id;
20
+ int quantity;
21
+ int action; /* buy or sell */
22
+ int fulfilled;
23
+ pthread_mutex_t lock;
24
+ pthread_cond_t finish;
25
+ };
26
+
27
+ struct order_que
28
+ {
29
+ struct order **orders;
30
+ int size;
31
+ int head;
32
+ int tail;
33
+ pthread_mutex_t lock;
34
+ pthread_cond_t full;
35
+ pthread_cond_t empty;
36
+ };
37
+
38
+ struct market
39
+ {
40
+ pthread_mutex_t lock;
41
+ int *stocks;
42
+ int count;
43
+ };
44
+
45
+ struct order *InitOrder(int id, int quantity, int action)
46
+ {
47
+ struct order *order;
48
+
49
+ order = (struct order *)malloc(sizeof(struct order));
50
+ if(order == NULL) {
51
+ return(NULL);
52
+ }
53
+ order->stock_id = id;
54
+ order->quantity = quantity;
55
+ order->action = action;
56
+ order->fulfilled = 0;
57
+ pthread_mutex_init(&order->lock,NULL);
58
+ pthread_cond_init(&order->finish,NULL);
59
+ return(order);
60
+ }
61
+
62
+ void FreeOrder(struct order *order)
63
+ {
64
+ free(order);
65
+ }
66
+
67
+ struct order_que *InitOrderQue(int size)
68
+ {
69
+ struct order_que *oq;
70
+
71
+ oq = (struct order_que *)malloc(sizeof(struct order_que));
72
+ if(oq == NULL) {
73
+ return(NULL);
74
+ }
75
+ memset(oq,0,sizeof(struct order_que));
76
+
77
+ oq->size = size+1; /* empty condition burns a slot */
78
+ oq->orders = (struct order **)malloc(oq->size*sizeof(struct order *));
79
+ if(oq->orders == NULL) {
80
+ free(oq);
81
+ return(NULL);
82
+ }
83
+ memset(oq->orders,0,size*sizeof(struct order *));
84
+
85
+ pthread_mutex_init(&oq->lock,NULL);
86
+ pthread_cond_init(&oq->full,NULL);
87
+ pthread_cond_init(&oq->empty,NULL);
88
+
89
+ return(oq);
90
+ }
91
+
92
+ void FreeOrderQue(struct order_que *oq)
93
+ {
94
+ while(oq->head != oq->tail) {
95
+ FreeOrder(oq->orders[oq->tail]);
96
+ oq->tail = (oq->tail + 1) % oq->size;
97
+ }
98
+
99
+ free(oq->orders);
100
+ free(oq);
101
+ return;
102
+ }
103
+
104
+ struct market *InitMarket(int stock_count, int init_quantity)
105
+ {
106
+ struct market *m;
107
+ int i;
108
+
109
+ m = (struct market *)malloc(sizeof(struct market));
110
+ if(m == NULL) {
111
+ return(NULL);
112
+ }
113
+ m->count = stock_count;
114
+
115
+ m->stocks = (int *)malloc(stock_count*sizeof(int));
116
+ if(m->stocks == NULL) {
117
+ free(m);
118
+ return(NULL);
119
+ }
120
+
121
+ for(i=0; i < stock_count; i++) {
122
+ m->stocks[i] = init_quantity;
123
+ }
124
+
125
+ pthread_mutex_init(&m->lock,NULL);
126
+
127
+ return(m);
128
+ }
129
+
130
+ void FreeMarket(struct market *m)
131
+ {
132
+ free(m->stocks);
133
+ free(m);
134
+ return;
135
+ }
136
+
137
+ void PrintMarket(struct market *m)
138
+ {
139
+ int i;
140
+ for(i=0; i < m->count; i++) {
141
+ printf("stock: %d, quantity: %d\n",
142
+ i,m->stocks[i]);
143
+ }
144
+
145
+ return;
146
+ }
147
+
148
+ struct client_arg
149
+ {
150
+ int id;
151
+ int order_count;
152
+ struct order_que *order_que;
153
+ int max_stock_id;
154
+ int max_quantity;
155
+ int verbose;
156
+ };
157
+
158
+ struct trader_arg
159
+ {
160
+ int id;
161
+ struct order_que *order_que;
162
+ struct market *market;
163
+ int *done;
164
+ int verbose;
165
+ };
166
+
167
+ void *ClientThread(void *arg)
168
+ {
169
+ struct client_arg *ca = (struct client_arg *)arg;
170
+ int i;
171
+ int next;
172
+ struct order *order;
173
+ int stock_id;
174
+ int quantity;
175
+ int action;
176
+ int queued;
177
+ double now;
178
+
179
+
180
+ for(i=0; i < ca->order_count; i++) {
181
+ /*
182
+ * create an order for a random stock
183
+ */
184
+ stock_id = (int)(RAND() * ca->max_stock_id);
185
+ quantity = (int)(RAND() * ca->max_quantity);
186
+ if(RAND() > 0.5) {
187
+ action = 0; /* 0 => buy */
188
+ } else {
189
+ action = 1; /* 1 => sell */
190
+ }
191
+ order = InitOrder(stock_id,quantity,action);
192
+ if(order == NULL) {
193
+ fprintf(stderr,"no space for order\n");
194
+ exit(1);
195
+ }
196
+ /*
197
+ * queue it for the traders
198
+ */
199
+ queued = 0;
200
+ while(queued == 0) {
201
+ pthread_mutex_lock(&(ca->order_que->lock));
202
+ next = (ca->order_que->head + 1) % ca->order_que->size;
203
+ /*
204
+ * is the queue full?
205
+ */
206
+ while(next == ca->order_que->tail) {
207
+ pthread_cond_wait(&(ca->order_que->full),
208
+ &(ca->order_que->lock));
209
+ next = (ca->order_que->head + 1) % ca->order_que->size;
210
+ }
211
+ /*
212
+ * there is space in the queue, add the order and bump
213
+ * the head
214
+ */
215
+ if(ca->verbose == 1) {
216
+ now = CTimer();
217
+ printf("%10.0f client %d: ",now,ca->id);
218
+ printf("queued stock %d, for %d, %s\n",
219
+ order->stock_id,
220
+ order->quantity,
221
+ (order->action ? "SELL" : "BUY"));
222
+ }
223
+ ca->order_que->orders[next] = order;
224
+ ca->order_que->head = next;
225
+ queued = 1;
226
+ pthread_cond_signal(&(ca->order_que->empty));
227
+ pthread_mutex_unlock(&(ca->order_que->lock));
228
+
229
+ /*
230
+ * wait using condition variable until
231
+ * order is fulfilled
232
+ */
233
+ pthread_mutex_lock(&order->lock);
234
+ while(order->fulfilled == 0) {
235
+ pthread_cond_wait(&order->finish,&order->lock);
236
+ }
237
+ pthread_mutex_unlock(&order->lock);
238
+ /*
239
+ * done, free the order and repeat
240
+ */
241
+ FreeOrder(order);
242
+ }
243
+ }
244
+
245
+ return(NULL);
246
+ }
247
+
248
+ void *TraderThread(void *arg)
249
+ {
250
+ struct trader_arg *ta = (struct trader_arg *)arg;
251
+ int dequeued;
252
+ struct order *order;
253
+ int tail;
254
+ double now;
255
+ int next;
256
+
257
+ while(1) {
258
+ dequeued = 0;
259
+ while(dequeued == 0) {
260
+ pthread_mutex_lock(&(ta->order_que->lock));
261
+ /*
262
+ * is the queue empty?
263
+ */
264
+ while(ta->order_que->head == ta->order_que->tail) {
265
+ /*
266
+ * if the queue is empty, are we done?
267
+ */
268
+ if(*(ta->done) == 1) {
269
+ pthread_cond_signal(&(ta->order_que->empty));
270
+ pthread_mutex_unlock(&(ta->order_que->lock));
271
+ pthread_exit(NULL);
272
+ }
273
+ pthread_cond_wait(&(ta->order_que->empty),
274
+ &(ta->order_que->lock));
275
+ }
276
+ /*
277
+ * get the next order
278
+ */
279
+ next = (ta->order_que->tail + 1) % ta->order_que->size;
280
+ order = ta->order_que->orders[next];
281
+ ta->order_que->tail = next;
282
+ pthread_cond_signal(&(ta->order_que->full));
283
+ pthread_mutex_unlock(&(ta->order_que->lock));
284
+ dequeued = 1;
285
+ }
286
+ /*
287
+ * have an order to process
288
+ */
289
+ pthread_mutex_lock(&(ta->market->lock));
290
+ if(order->action == 1) { /* BUY */
291
+ ta->market->stocks[order->stock_id] -= order->quantity;
292
+ if(ta->market->stocks[order->stock_id] < 0) {
293
+ ta->market->stocks[order->stock_id] = 0;
294
+ }
295
+ } else {
296
+ ta->market->stocks[order->stock_id] += order->quantity;
297
+ }
298
+ pthread_mutex_unlock(&(ta->market->lock));
299
+ if(ta->verbose == 1) {
300
+ now = CTimer();
301
+ printf("%10.0f trader: %d ",now,ta->id);
302
+ printf("fulfilled stock %d for %d\n",
303
+ order->stock_id,
304
+ order->quantity);
305
+ }
306
+ /*
307
+ * tell the client the order is done
308
+ */
309
+ pthread_mutex_lock(&order->lock);
310
+ order->fulfilled = 1;
311
+ pthread_cond_signal(&order->finish);
312
+ pthread_mutex_unlock(&order->lock);
313
+ }
314
+
315
+ return(NULL);
316
+ }
317
+
318
+ #define ARGS "c:t:o:q:s:V"
319
+ char *Usage = "market1 -c clients -t traders -o orders -q queue-size -s stock-count -V <verbose on>\n";
320
+
321
+ #define INIT_COUNT 5000
322
+
323
+ int main(int argc, char **argv)
324
+ {
325
+ int c;
326
+ int client_threads;
327
+ int trader_threads;
328
+ int orders_per_client;
329
+ int que_size;
330
+ int max_stock;
331
+ int verbose;
332
+ struct client_arg *ca;
333
+ struct trader_arg *ta;
334
+ pthread_t *client_ids;
335
+ pthread_t *trader_ids;
336
+ struct order_que *order_que;
337
+ struct market *market;
338
+ int i;
339
+ int done;
340
+ int err;
341
+ double start;
342
+ double end;
343
+
344
+
345
+ /*
346
+ * defaults
347
+ */
348
+ client_threads = 1;
349
+ trader_threads = 1;
350
+ orders_per_client = 1;
351
+ verbose = 0;
352
+ que_size = 1;
353
+ max_stock = 1;
354
+
355
+ while((c = getopt(argc,argv,ARGS)) != EOF) {
356
+ switch(c) {
357
+ case 'c':
358
+ client_threads = atoi(optarg);
359
+ break;
360
+ case 't':
361
+ trader_threads = atoi(optarg);
362
+ break;
363
+ case 'o':
364
+ orders_per_client = atoi(optarg);
365
+ break;
366
+ case 'q':
367
+ que_size = atoi(optarg);
368
+ break;
369
+ case 's':
370
+ max_stock = atoi(optarg);
371
+ break;
372
+ case 'V':
373
+ verbose = 1;
374
+ break;
375
+ default:
376
+ fprintf(stderr,
377
+ "unrecognized command %c\n",
378
+ (char)c);
379
+ fprintf(stderr,"usage: %s",Usage);
380
+ exit(1);
381
+ }
382
+ }
383
+
384
+ client_ids = (pthread_t *)malloc(client_threads*sizeof(pthread_t));
385
+ if(client_ids == NULL) {
386
+ exit(1);
387
+ }
388
+
389
+ ca = (struct client_arg *)malloc(client_threads*sizeof(struct client_arg));
390
+ if(ca == NULL) {
391
+ exit(1);
392
+ }
393
+
394
+ trader_ids = (pthread_t *)malloc(trader_threads*sizeof(pthread_t));
395
+ if(trader_ids == NULL) {
396
+ exit(1);
397
+ }
398
+
399
+ ta = (struct trader_arg *)malloc(trader_threads*sizeof(struct trader_arg));
400
+ if(ta == NULL) {
401
+ exit(1);
402
+ }
403
+
404
+ order_que = InitOrderQue(que_size);
405
+ if(order_que == NULL) {
406
+ exit(1);
407
+ }
408
+
409
+ market = InitMarket(max_stock,INIT_COUNT);
410
+ if(market == NULL) {
411
+ exit(1);
412
+ }
413
+
414
+ start = CTimer();
415
+ for(i=0; i < client_threads; i++) {
416
+ ca[i].id = i;
417
+ ca[i].order_count = orders_per_client;
418
+ ca[i].max_stock_id = max_stock;
419
+ ca[i].max_quantity = INIT_COUNT;
420
+ ca[i].order_que = order_que;
421
+ ca[i].verbose = verbose;
422
+ err = pthread_create(&client_ids[i],NULL,
423
+ ClientThread,(void *)&ca[i]);
424
+ if(err != 0) {
425
+ fprintf(stderr,"client thread create %d failed\n",i);
426
+ exit(1);
427
+ }
428
+ }
429
+
430
+ done = 0;
431
+ for(i=0; i < trader_threads; i++) {
432
+ ta[i].id = i;
433
+ ta[i].order_que = order_que;
434
+ ta[i].market = market;
435
+ ta[i].done = &done;
436
+ ta[i].verbose = verbose;
437
+ err = pthread_create(&trader_ids[i],NULL,
438
+ TraderThread,(void *)&ta[i]);
439
+ if(err != 0) {
440
+ fprintf(stderr,"trader thread create %d failed\n",i);
441
+ exit(1);
442
+ }
443
+ }
444
+
445
+ /*
446
+ * wait for the clients to finish
447
+ */
448
+ for(i=0; i < client_threads; i++) {
449
+ err = pthread_join(client_ids[i],NULL);
450
+ if(err != 0) {
451
+ fprintf(stderr,"client join %d failed\n",i);
452
+ exit(1);
453
+ }
454
+ }
455
+
456
+ /*
457
+ * tell the traders we are done
458
+ */
459
+ pthread_mutex_lock(&order_que->lock);
460
+ done = 1;
461
+ pthread_cond_signal(&order_que->empty);
462
+ pthread_mutex_unlock(&order_que->lock);
463
+
464
+ for(i=0; i < trader_threads; i++) {
465
+ err = pthread_join(trader_ids[i],NULL);
466
+ if(err != 0) {
467
+ fprintf(stderr,"trader join %d failed\n",i);
468
+ exit(1);
469
+ }
470
+ }
471
+ end = CTimer();
472
+
473
+ if(verbose == 1) {
474
+ PrintMarket(market);
475
+ }
476
+
477
+ printf("%f transactions / sec\n",
478
+ (double)(orders_per_client*client_threads) / (end-start));
479
+
480
+ free(ca);
481
+ free(ta);
482
+ free(client_ids);
483
+ free(trader_ids);
484
+ FreeMarket(market);
485
+ FreeOrderQue(order_que);
486
+
487
+ return(0);
488
+ }
489
+
490
+
491
+
492
+
493
+
494
+
495
+
496
+
497
+
498
+
499
+
500
+
501
+
502
+
503
+