- 论坛徽章:
- 0
|
本帖最后由 xvhfeng 于 2011-03-28 17:31 编辑
- #include <stdio.h>
- #include <stdlib.h>
- #include <gc.h>
- #include <string.h>
- #incude <gc/gc_pthread_redirects.h>
- void *run(void *arg);
- struct gc_test
- {
- int id;
- char *value;
- };
- int main(int argc,char** argv)
- {
- GC_INIT();
- int i = 0;
- pthread_t threadid[10];
- for(i = 0; i < 10; i++)
- {
- GC_pthread_create(&(threadid[i]),NULL,run,NULL);
- }
- }
- void *run(void *arg)
- {
- int i;
- struct gc_test *obj =(struct gc_test*) GC_MALLOC(sizeof(struct gc_test));
- for(i = 0; i<100000; i++)
- {
- obj->id = i;
- obj->value = (char *)GC_MALLOC_ATOMIC(i * sizeof(char));
- memset(obj->value,0,i);
- printf("%d\n",i);
- }
- }
- 安装gc时,configure 参数为:--enable-threads=posix --enable-thread-local-alloc --enable-parallel-mark
- 系统为ubuntu 10.04 32位
- 编译:
- gcc -g test_gc.c -I/usr/local/include -L/usr/local/lib/ -lgc -lpthread -o test
复制代码 这是我写的最简单的测试代码,运行时会报SUGPWR!有大侠能指教吗? |
|