Permalink
Browse files

multithreaded question

Adding famous interview q.
  • Loading branch information...
chintan09 committed Nov 16, 2011
1 parent 446e12f commit 36a1fad28c308670ae0570f1c879c730936cd549
Showing with 24 additions and 0 deletions.
  1. +2 −0 README
  2. +22 −0 helper.c
View
2 README
@@ -11,3 +11,5 @@ todo:
draw a circle
code for testing a mutex
linked list, stack, queue etc.
+add doxygen
+mulitply all elements in an array with each other in order of N
View
@@ -53,6 +53,7 @@ void matrix_mul()
}
+#ifdef INTERVIEW_CODE
/* Interview trick question on stack */
void stackoverflow()
{
@@ -64,3 +65,24 @@ void stackoverflow()
printf("%d \n", a[i]);
}
}
+
+/* Multithreaded question */
+void bar (void)
+{
+ int *m;
+ m = calloc(sizeof(int));
+ if (fork())
+ {
+ while (*m == 0); *m = 0;
+ printf("a");
+ }
+ else
+ {
+ *m = 1; while (*m);
+ printf("b");
+ }
+ exit();
+}
+
+
+#endif

0 comments on commit 36a1fad

Please sign in to comment.