c++ - pthread_create(), how do I get the returned value from the passed function -
How do I get zero return to the function passing the pthread_create?
static zero * pthread_sendRequest (zero * name) {RequestChannel chan (* (string *) name, RequestChannel :: CLIENT_SIDE); String Return Value = chan.send_request ("hi"); Return (zero *) and return value; } Pthread_create (thread, null, pthread_sendRequest, new string (& amp; "employee #" [i]));
How do I get the return value of pthread_sendRequest, when it is sent to pthread_ create, then I can bring it back to the string pointer and Can I get the actual string?
is zero ** pthread_join (thread, zero **) Hold it for me?
As the other answer indicates, the value received from the thread function receives the value received by that buffer to do.
However, in your example, your thread function is returning a pointer to a non-fixed local variable, which is invalid (even if the function is executed in a thread) because once the function is out The local object is no longer present when it is gone.
You can do something like this:
static zero * pthread_sendRequest (zero * name) {RequestChannel chan (* * string *) name, request channel :: CLIENT_SIDE ); String * returnValue = new string (chan.send_request ("hi"); Return (zero *) return value; } Pthread_create (thread, null, pthread_sendRequest, new string (& amp; "employee #" [i])); // ... zero * temp = NULL; Pthread_join (* Thread, and Temporary); String * returnValue = (string *) temporary; // When the return is done with the value of return value;
Comments
Post a Comment