- 论坛徽章:
- 0
|
我这里简单写下相关逻辑:
int *g_errno_p;
void print_errno(void)
{
int tmp_fd = 0;
tmp_fd = open("/config/aaaa.txt", O_RDONLY);
if(tmp_fd < 0)
{
printf("[%d][%s]\r\n", errno, strerrno(errno));
}
printf("[%p][%d], [%p][%d]\r\n", __errno_location, *(__errno_location), g_errno_p, *(g_errno_p));//实际打印结果是,主线程与子线程的__errno_location地址不同,并且线程中的错误码写到了主进程中
}
void main(void)
{
g_errno_p = __errno_location;//记录主进程errno地址;
int tmp_fd = 0;
tmp_fd = open("/config/aaaa.txt", O_RDONLY);
if(tmp_fd < 0)
{
printf("[%d][%s]\r\n", errno, strerrno(errno));
}
printf("[%p][%d]\r\n", __errno_location, *(__errno_location));
pthread_t tid1;
pthread_create( &tid1, NULL, (void *)print_errno, NULL );
}
目前的现象就是,线程中的错误码写到了主进程的错误码中,所以子线程中的错误码一直都是0
回复 5# MMMIX
|
|