Skip to content

Instantly share code, notes, and snippets.

@toddlipcon
Created February 20, 2019 05:04
Show Gist options
  • Save toddlipcon/4e0fecfba851f5f4d8652815a2834512 to your computer and use it in GitHub Desktop.
Save toddlipcon/4e0fecfba851f5f4d8652815a2834512 to your computer and use it in GitHub Desktop.
#include <krb5/krb5.h>
#include <iostream>
#include <functional>
#include <atomic>
#include <cassert>
#include <unistd.h>
#include <thread>
#include <vector>
using namespace std;
int main(int argc, char** argv) {
krb5_context ctx;
int rc = krb5_init_context(&ctx);
assert(rc == 0);
atomic<int> state { 0 };
vector<thread> threads;
for (int i = 0; i < 10; i++) {
threads.emplace_back([&]() {
while (state == 0) {}
while (state == 1) {
krb5_principal princ;
int rc = krb5_parse_name(ctx, "foo", &princ);
if (rc != 0) {
std::unique_ptr<const char, std::function<void(const char*)>> err_msg(
krb5_get_error_message(ctx, rc),
bind(krb5_free_error_message, ctx, std::placeholders::_1));
cerr << "err: " << err_msg.get() << endl;
abort();
}
krb5_free_principal(ctx, princ);
}
});
}
state = 1;
sleep(1);
state = 2;
for (auto& t : threads) t.join();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment