pthreads, printf and cout
Alex Vinokur
alexvn at connect.to
Fri Jan 2 12:14:08 UTC 2004
Hi,
Behavior of printf and cout in a program below is different : cout prints nothing.
What is wrong?
===================================
Windows 2000 Professional
CYGWIN_NT-5.0 1.5.4(0.94/3/2)
gcc version 3.3.1 (cygming special)
===================================
====== C++ code : foo.cpp : BEGIN ======
#include <stdio.h>
#include <iostream>
#include <pthread.h>
#include <unistd.h>
using namespace std;
extern "C" void* Run(void *)
{
printf ("printf : Run Start\n");
cout << "cout : Run Start" << endl;
sleep (3);
printf ("printf : Run Finish\n");
cout << "cout : Run Finish" << endl;
}
int main ()
{
pthread_t t1;
pthread_create(&t1, NULL, Run, NULL);
int errNum = pthread_join(t1, NULL);
printf ("printf : errNum = %d\n", errNum);
cout << "cout : errNum = " << errNum << endl;
}
====== C++ code : foo.cpp : END ========
====== Compilation & Run : BEGIN ======
$ g++ foo.cpp
$ a
printf : Run Start
printf : Run Finish
printf : errNum = 0
// cout prints nothing
====== Compilation & Run : END ========
--
=====================================
Alex Vinokur
mailto:alexvn at connect.to
http://mathforum.org/library/view/10978.html
news://news.gmane.org/gmane.comp.lang.c++.perfometer
=====================================
More information about the c++-pthreads
mailing list