免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: jiahehao
打印 上一主题 下一主题

线程修改了static全局变量,其它函数来读却没有变化? [复制链接]

论坛徽章:
0
11 [报告]
发表于 2012-04-12 17:39 |只看该作者
#include <stdio.h>
#include <stdlib.h>

static int p_portstate[6];

void loop_thread_fun()
{
        int i;
        for (i = 0; i < 6; i++)
                p_portstate[i] = i + 5;
}

int main_loop_back(void)
{
  pthread_t tid;
  int error;
  error=pthread_create(&tid,NULL,loop_thread_fun,NULL);
  if(error!=0)
  {
  printf("thread is not created...\n");
return -1;
  }  printf("create thread succes, main pid is %d\n",getpid());
  return 0;
}


int main(void)
{
        int i;

        main_loop_back();
        for (i = 0; i < 6; i++)
                printf("%d  ", p_portstate[i]);
        printf("\n");

        return 0;
}

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP