ALL


  A trick of building multithreaded application on Solaris

Firstly, Let’s see a simple multithreaded application:#include <stdio.h>#include <pthread.h>#include <errno.h>void *thread1_func(void *p_arg){ errno = 0; sleep(3); errno = 1; printf("%s exit, errno is %d\n", (char*)p_arg, errno);}void *thread2_func(void *p_arg){ errno = 0; sleep(5); printf("%s exit, errno is %d\n", (char*)p_arg, errno);}int main(void){ pthread_t t1, t2; pthread_create(&t1, NULL, thread1_func, "Thread 1"); pthread_create(&t2, NULL, thread2_func, "Thread 2")...

5,428 0       C SOLARIS


  An experience of fixing a memory-corruption bug

During the last 4 months, I was disturbed by a memory-corruption bug, and this bug will cause program crash. Until last Monday, I found the root cause and fixed it. This debug process is a difficult but memorable experience, so I will share it in this article. My program works as a SMS Hub. When it receives a SMS, it will allocate a structure in heap memory like this:typedef struct{ ...... int *a[8]; ......} info;After processing the SMS, the program will free the memory, and send the SMS to the next Hub or Operator.  Since last November, the program will crash som...

9,018 0       C UNIX DEBUG SOLARIS MULTI-THREAD