Skip to content

Instantly share code, notes, and snippets.

@xjdrew
Created November 25, 2014 11:23
Show Gist options
  • Save xjdrew/57fedd243730032a00f2 to your computer and use it in GitHub Desktop.
Save xjdrew/57fedd243730032a00f2 to your computer and use it in GitHub Desktop.
vs printf/std:cout bug
#include <stdlib.h>
#include <process.h>
#include <iostream>
void work1(void* p)
{
while (1) {
printf("hello world");
_sleep(1);
}
}
void work2(void* p)
{
while (1) {
std::cout << "hello world";
_sleep(1);
}
}
int main()
{
for (size_t i = 0; i < 100; i++)
{
_beginthread(work1, 0, NULL);
}
for (size_t i = 0; i < 100; i++)
{
_beginthread(work2, 0, NULL);
}
while (1)
{
_sleep(10000);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment