0

Hi,

I'm embedded c coder and relatively new to c++. I'm working with borland 6.
What i'm trying to do is call my "SerialThread" named worker thread which processes the line.

Call

//char input_sentence[9]; this includes the textline "ANGLE 360"
char * buff = input_sentence;
 thread = _beginthread( SerialThread, 8192, (void *)&buff);

This thread version gives access violation

void SerialThread( void *input)
{

     char *  line = *(char**)input;
     Fmain->Memo1->Lines->Append(line);
     _endthread();
}

This version outputs character "T".

void SerialThread( void *input)
{

     char  line = *(char*)input;
     Fmain->Memo1->Lines->Append(line);
     _endthread();
}

Tried with string but got std::bad_alloc
If i just pass the input_sentence, i will get only first charachter to output.

Any help wil be appriciated.

3
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by f_rele
0

Are you sure that your input string is null terminated?

Thank you for your fast reply.

Yes it is null terminated. I forgot to mention that. There is input_sentence[times]=0; line just before the call.

0

do not pass the address of a local variable (with automatic storage duration) to a thread function; it may not be around by the time the thread executes.

// ...
char* input_sentence = new char[32];
std::strcpy( input_sentence, "ANGLE 360" ) ;
thread = _beginthread( SerialThread, 8192, input_sentence ) ;
// ...

void SerialThread( void* input )
{

     char*  line = static_cast<char*>(input) ;
     Fmain->Memo1->Lines->Append(line);
     delete [] line ;
     _endthread();
}
0

Thank you! Your reply really saved my day. I had spent 4 hours dealing with that issue.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.