Path: blob/main/crypto/krb5/src/ccapi/test/simple_lock_test.c
39536 views
/*1simple_lock_test.c23Initializes two contexts in two different threads and tries to get read locks on both at the same time.4Hangs at line 24.5*/6#include <stdio.h>7#include <stdarg.h>89#include "test_ccapi_log.h"1011#if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__))12#include <TargetConditionals.h>13#endif1415#ifdef TARGET_OS_MAC16#include <stdlib.h>17#include <pthread.h>18#include <Kerberos/CredentialsCache.h>19#else20#include "CredentialsCache.h"21#endif222324void *other_thread (void) {25cc_int32 err;26cc_context_t context = NULL;2728err = cc_initialize(&context, ccapi_version_7, NULL, NULL);2930log_error("thread: attempting lock. may hang. err == %d", err);3132if (!err) {33// hangs with cc_lock_read which should succeed immediately, but does not hang with write, upgrade, and downgrade, which fail immediately34err = cc_context_lock(context, cc_lock_read, cc_lock_noblock);35}3637if (context) {38cc_context_unlock(context);39cc_context_release(context);40context = NULL;41}42log_error("thread: return. err == %d", err);43}444546int main (int argc, char *argv[]) {47cc_int32 err;48int status;49cc_context_t context = NULL;5051#ifdef TARGET_OS_MAC52pthread_t thread_id;53#endif5455err = cc_initialize(&context, ccapi_version_7, NULL, NULL);56if (!err) {57err = cc_context_lock(context, cc_lock_read, cc_lock_noblock);58}5960log_error("main: initialized and read locked context. err == %d", err);6162#ifdef TARGET_OS_MAC63status = pthread_create (&thread_id, NULL, (void *) other_thread, NULL);64if (status != 0) {65log_error("pthread_create() returned %d", status);66exit(-1);67}6869pthread_join(thread_id, NULL);70#else7172#endif7374log_error("main: unlocking and releasing context. err == %d", err);7576if (context) {77log_error("main: calling cc_context_unlock");78cc_context_unlock(context);79log_error("main: calling cc_context_release");80cc_context_release(context);81context = NULL;82}8384log_error("main: return. err == %d", err);8586#if defined(_WIN32)87UNREFERENCED_PARAMETER(status); // no whining!88#endif89return 0;90}919293