Operating System - OpenVMS
1753834 Members
8407 Online
108806 Solutions
New Discussion

Re: Use Pthread[CMA-F-EXIT_THREAD]

 
SOLVED
Go to solution
Hoff
Honored Contributor

Re: Use Pthread[CMA-F-EXIT_THREAD]

What is the declaration of szSendSocketBuf here?

memset(&szSendSocketBuf, DEFINE_NULL, sizeof(szSendSocketBuf));

I can guess what DEFINE_NULL is, but do confirm that, too.

This memcpy statement may be an innocent bystander, too; the fault could be upstream.

I'd look to examine the values here, and see if I can find some code upstream to set watchpoints or to program the debugger to detect (the debugger supports conditionals) and break on the run-up to the error.

If the buffer is shared among threads, it's possible there's a collision. Interlocking among threads is required; it seems reasonable to expect untoward application behavior when a memset goes flying past when some other thread is busy reading the buffer, for instance.

I prefer to honor errors and signals (and compiler warnings). My general preference here (and unless I have specific reasons to the contrary) is to catch an (unexpected) error and to exit the application with a diagnostic. I've worked with more than a few cases where continuing after an error has shown a nasty habit of contributing to an error avalanche, or to triggering secondary and more subtle errors, Employing "catch and release" programming with errors is certainly possible, but requires great care.
JimsanTsai
Advisor

Re: Use Pthread[CMA-F-EXIT_THREAD]

Dear Hoff~
#define DEF_SEND_MSG_LENGTH 64000
char szSendSocketBuf[DEF_SEND_MSG_LENGTH+1]; /*Send Buffer(Socket)*/

There's only stThreadParam global variable in the application, and there's 16 of QueueSyncThread threads running concurrent.
The thread structure as follows:
----------------------------------------
typedef struct
{
char szStage[10];
char szGlobalSectionName[10];
}stThreadParam;

void* QueueSyncThread(void* pstthparam)
{
char szSendSocketBuf[DEF_SEND_MSG_LENGTH+1];
...(other variables)

/*get pstthparam value to local variable Process*/
/*Read Ini Process*/
/*Socket Connect to another Host*/

/*Initial Variable(memset)*/

while(1)
{
memset(&szSendSocketBuf, DEFINE_NULL, sizeof(szSendSocketBuf));
...(initial other variables)

/*mapping global section1*/
/*mapping global section2*/

/*socket send*/
/*socket recv*/

/*mapping global section3*/
/*mapping global section1*/
}
pthread_exit(NULL);
}
----------------------------------------
I didn't use the mutex in the thread(16 threads do the same things, but mapping different global section).
May I ask all variables in QueueSyncThread is share among threads?