Skip to content

Instantly share code, notes, and snippets.

@smichal
Created January 19, 2010 17:21
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 smichal/281101 to your computer and use it in GitHub Desktop.
Save smichal/281101 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "sched.h"
void starter()
{
mysched_thread_t current = mysched_self();
long long cntr = 0;
while (cntr < 10000000) {
++cntr;
if ((cntr + 1) % 100000 == 0) {
char buf[100];
int err;
char * name = mysched_get_name(current);
sprintf(buf, "this is thread %s (%Ld)\n", name, cntr);
err = mysched_pwrite(1, buf, strlen(buf) + 1, 0);
free(name);
if (err == -1) {
fprintf(stderr, "Error while using mysched_pwrite: %d (%s)", err, strerror(err));
abort();
}
}
}
}
int main(int const argc, char const * const * const argv)
{
mysched_init();
for(;;)
{
mysched_create_thread(starter, "test thread 1");
mysched_create_thread(starter, "test thread 2");
mysched_create_thread(starter, "test thread 3");
mysched_create_thread(starter, "test thread 4");
mysched_create_thread(starter, "test thread 5");
mysched_create_thread(starter, "test thread 6");
mysched_create_thread(starter, "test thread 7");
mysched_go();
mysched_create_thread(starter, "THREAD 1");
mysched_create_thread(starter, "THREAD 2");
mysched_go();
// for(;;);
}
printf("Successfuly returned\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment