-/*\r
- simple_lock_test.c\r
- \r
- Initializes two contexts in two different threads and tries to get read locks on both at the same time.\r
- Hangs at line 24.\r
-*/\r
-#include <stdio.h>\r
-#include <stdarg.h>\r
-\r
-#include "cci_debugging.h"\r
-\r
-#ifdef TARGET_OS_MAC\r
-#include <stdlib.h>\r
-#include <Kerberos/CredentialsCache.h>\r
-#else\r
-#include "CredentialsCache.h"\r
-#endif\r
-\r
-\r
-void * other_thread () {\r
- cc_int32 err;\r
- cc_context_t context = NULL;\r
- \r
- err = cc_initialize(&context, ccapi_version_7, NULL, NULL);\r
-\r
- cci_debug_printf("thread: attempting lock. may hang. err == %d", err);\r
-\r
- if (!err) {\r
- // hangs with cc_lock_read which should succeed immediately, but does not hang with write, upgrade, and downgrade, which fail immediately\r
- err = cc_context_lock(context, cc_lock_read, cc_lock_noblock);\r
- }\r
-\r
- if (context) {\r
- cc_context_unlock(context);\r
- cc_context_release(context);\r
- context = NULL;\r
- }\r
- cci_debug_printf("thread: return. err == %d", err);\r
- }\r
-\r
-\r
-int main (int argc, char *argv[]) {\r
- cc_int32 err;\r
- int status;\r
- cc_context_t context = NULL;\r
-\r
-#ifdef TARGET_OS_MAC\r
- pthread_t thread_id;\r
-#endif\r
-\r
- err = cc_initialize(&context, ccapi_version_7, NULL, NULL);\r
- if (!err) {\r
- err = cc_context_lock(context, cc_lock_read, cc_lock_noblock);\r
- }\r
- \r
- cci_debug_printf("main: initialized and read locked context. err == %d", err);\r
-\r
-#ifdef TARGET_OS_MAC\r
- status = pthread_create (&thread_id, NULL, (void *) other_thread, NULL);\r
- if (status != 0) {\r
- cci_debug_printf("Create error!");\r
- exit(-1);\r
- }\r
-\r
- pthread_join(thread_id, NULL);\r
-#else\r
-\r
-#endif\r
- \r
- cci_debug_printf("main: unlocking and releasing context. err == %d", err);\r
- \r
- if (context) {\r
- cci_debug_printf("main: calling cc_context_unlock");\r
- cc_context_unlock(context);\r
- cci_debug_printf("main: calling cc_context_release");\r
- cc_context_release(context);\r
- context = NULL;\r
- }\r
-\r
- cci_debug_printf("main: return. err == %d", err);\r
- \r
- UNREFERENCED_PARAMETER(status); // no whining!\r
- return 0;\r
+/*
+ simple_lock_test.c
+
+ Initializes two contexts in two different threads and tries to get read locks on both at the same time.
+ Hangs at line 24.
+*/
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "cci_debugging.h"
+
+#ifdef TARGET_OS_MAC
+#include <stdlib.h>
+#include <Kerberos/CredentialsCache.h>
+#else
+#include "CredentialsCache.h"
+#endif
+
+
+void * other_thread () {
+ cc_int32 err;
+ cc_context_t context = NULL;
+
+ err = cc_initialize(&context, ccapi_version_7, NULL, NULL);
+
+ cci_debug_printf("thread: attempting lock. may hang. err == %d", err);
+
+ if (!err) {
+ // hangs with cc_lock_read which should succeed immediately, but does not hang with write, upgrade, and downgrade, which fail immediately
+ err = cc_context_lock(context, cc_lock_read, cc_lock_noblock);
+ }
+
+ if (context) {
+ cc_context_unlock(context);
+ cc_context_release(context);
+ context = NULL;
+ }
+ cci_debug_printf("thread: return. err == %d", err);
+ }
+
+
+int main (int argc, char *argv[]) {
+ cc_int32 err;
+ int status;
+ cc_context_t context = NULL;
+
+#ifdef TARGET_OS_MAC
+ pthread_t thread_id;
+#endif
+
+ err = cc_initialize(&context, ccapi_version_7, NULL, NULL);
+ if (!err) {
+ err = cc_context_lock(context, cc_lock_read, cc_lock_noblock);
+ }
+
+ cci_debug_printf("main: initialized and read locked context. err == %d", err);
+
+#ifdef TARGET_OS_MAC
+ status = pthread_create (&thread_id, NULL, (void *) other_thread, NULL);
+ if (status != 0) {
+ cci_debug_printf("Create error!");
+ exit(-1);
+ }
+
+ pthread_join(thread_id, NULL);
+#else
+
+#endif
+
+ cci_debug_printf("main: unlocking and releasing context. err == %d", err);
+
+ if (context) {
+ cci_debug_printf("main: calling cc_context_unlock");
+ cc_context_unlock(context);
+ cci_debug_printf("main: calling cc_context_release");
+ cc_context_release(context);
+ context = NULL;
+ }
+
+ cci_debug_printf("main: return. err == %d", err);
+
+ UNREFERENCED_PARAMETER(status); // no whining!
+ return 0;
}
\ No newline at end of file