- 论坛徽章:
- 0
|
实验有问题吗?
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <pthread.h>
- extern int errno;
- unsigned int ewok;
- void *MallocTest(void *arg)
- {
- int *mem;
- unsigned long count = 0;
- int id = ewok;
- while(1)
- {
- mem = malloc(1024);
- if(!(count % 10000))
- {
- printf("count %d: 0x%08lx\n", id, mem);
- }
- free(mem);
- count++;
- }
- }
- int main()
- {
- pthread_t temp_thread;
- pthread_create(&temp_thread, NULL, MallocTest, NULL);
- ewok++;
- sleep(5);
- pthread_create(&temp_thread, NULL, MallocTest, NULL);
- ewok++;
- sleep(5);
- pthread_create(&temp_thread, NULL, MallocTest, NULL);
- ewok++;
- sleep(5);
- while(1){}
- return 0;
- }
复制代码 |
|