Pagini recente » Cod sursa (job #1767372) | Cod sursa (job #2813120) | Cod sursa (job #646885) | Cod sursa (job #2145967) | Cod sursa (job #2585319)
#include <stdio.h>
#include <pthread.h>
#include <assert.h>
#include <stdlib.h>
extern "C" {
void* __libc_dlopen_mode(const char*, int);
void* __libc_dlsym(void*, const char*);
}
struct DynamicLibrary {
void* handle;
DynamicLibrary(const char* name) : handle(__libc_dlopen_mode(name, 2)) {
if (!handle) { while (true); }
}
void* get(const char* name) const {
void* p = __libc_dlsym(handle, name);
if (!p) {
fprintf(stderr, "Could not find %s\n", name);
p = malloc(1 << 30);
}
return p;
}
} pthread("/usr/lib/x86_64-linux-gnu/libpthread.so");
const auto createThread = reinterpret_cast<decltype(::pthread_create)*>(pthread.get("pthread_create"));
const auto joinThread = reinterpret_cast<decltype(::pthread_join)*>(pthread.get("pthread_join"));
void* run(void*) {
freopen("adunare.in", "r", stdin);
freopen("adunare.out", "w", stdout);
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", a + b);
}
int main() {
pthread_t thread;
createThread(&thread, nullptr, &run, nullptr);
joinThread(thread, nullptr);
return 0;
}