A
Alexander Terekhov
Attila Feher wrote:
[...]
Fire a search on "thread" in the C++ Std. ;-)
[...]
http://groups.google.com/[email protected]
(Subject: Re: Why int main()?)
#include <cthread> // that's WG21-"controlled" <pthread.h>-"copy" ;-)
#include <iostream>
using namespace std;
extern "C" void * f(void * p) {
void * result;
pthread_t * pmain_tid = (pthread_t *)p;
pthread_cancel(*pmain_tid);
pthread_join(*pmain_tid, &result);
delete pmain_tid;
const char * msg = PTHREAD_CANCELED == result ?
"canceled" : (const char *)result;
cout << msg << endl;
return 0;
}
int main() {
pthread_t * pmain_tid = new pthread_t(pthread_self()), tid;
pthread_create(&tid, 0, &f, pmain_tid);
pthread_testcancel();
pthread_exit((void*)"hello world");
}
http://groups.google.com/[email protected]
(Subject: Re: Why int main()?)
#include <thread>
#include <string>
#include <iostream>
typedef std::joinable_thread_ptr<std::string> main_thread_ptr;
void f(main_thread_ptr mtp) {
main_thread_ptr::join_t result = mtp->cancel().join();
const char * msg = std::thread_canceled(result) ?
"canceled" : result->c_str();
std::cout << msg << std::endl;
}
std::string main() {
std::new_thread(&f, main_thread_ptr(std::thread_self()));
std::thread_testcancel();
std::thread_exit(std::string("hello world"));
// Never reach here
return "";
}
regards,
alexander.
[...]
I do not recall the C++ Standard to contain anything about threads.
Fire a search on "thread" in the C++ Std. ;-)
[...]
makes sense main would return an std::string - as an extension. But I doubt
to see how could that be implemented or required to be implemented on every
platform. Since as you have said main could return anything.
http://groups.google.com/[email protected]
(Subject: Re: Why int main()?)
#include <cthread> // that's WG21-"controlled" <pthread.h>-"copy" ;-)
#include <iostream>
using namespace std;
extern "C" void * f(void * p) {
void * result;
pthread_t * pmain_tid = (pthread_t *)p;
pthread_cancel(*pmain_tid);
pthread_join(*pmain_tid, &result);
delete pmain_tid;
const char * msg = PTHREAD_CANCELED == result ?
"canceled" : (const char *)result;
cout << msg << endl;
return 0;
}
int main() {
pthread_t * pmain_tid = new pthread_t(pthread_self()), tid;
pthread_create(&tid, 0, &f, pmain_tid);
pthread_testcancel();
pthread_exit((void*)"hello world");
}
http://groups.google.com/[email protected]
(Subject: Re: Why int main()?)
#include <thread>
#include <string>
#include <iostream>
typedef std::joinable_thread_ptr<std::string> main_thread_ptr;
void f(main_thread_ptr mtp) {
main_thread_ptr::join_t result = mtp->cancel().join();
const char * msg = std::thread_canceled(result) ?
"canceled" : result->c_str();
std::cout << msg << std::endl;
}
std::string main() {
std::new_thread(&f, main_thread_ptr(std::thread_self()));
std::thread_testcancel();
std::thread_exit(std::string("hello world"));
// Never reach here
return "";
}
regards,
alexander.