Skip to content

Instantly share code, notes, and snippets.

@moyix
Last active June 25, 2016 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moyix/a49ae005cbcdc2853863a6c461904b73 to your computer and use it in GitHub Desktop.
Save moyix/a49ae005cbcdc2853863a6c461904b73 to your computer and use it in GitHub Desktop.
.global do_rdrand
/* Signature: uint32_t do_rdrand(void); */
do_rdrand:
.Lrdrand_retry:
rdrand %rax
jc .Lrdrand_retry /* Fail? */
ret
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <pthread.h>
uint32_t do_rdrand(void);
void * threadfunc(void *unused) {
printf("Value: %08x\n", do_rdrand());
return NULL;
}
int main(int argc, char **argv) {
int nThread = atoi(argv[1]);
pthread_t *threads = (pthread_t *) malloc(nThread * sizeof(pthread_t));
for (int i = 0; i < nThread; i++) {
pthread_create(&threads[i], NULL, threadfunc, NULL);
}
for (int i = 0; i < nThread; i++) {
pthread_join(threads[i], NULL);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment