Пример #1
0
int main(void){
  struct foo *fo;
  struct foo *fo2;
  struct foo *fo_find;
  int a=12;
  
  fo=foo_alloc(a);  
  printf("f_count=%d,f_id=%d\n",fo->f_count,fo->f_id);
  
  foo_hold(fo);
  printf("f_count=%d,f_id=%d\n",fo->f_count,fo->f_id);
  

  foo_rele(fo);
  printf("f_count=%d,f_id=%d\n",fo->f_count,fo->f_id);
  
  fo_find=foo_find(1);
  printf("foo_find f_count=%d,f_id=%d\n",fo_find->f_count,fo_find->f_id);

  printf("----\n");
  int b=13;
  fo2=foo_alloc(b);
  printf("f_count=%d,f_id=%d\n",fo2->f_count,fo2->f_id);

  exit(0);
}
Пример #2
0
int main(void) {
	int			err, i;
	pthread_t	tid;

	if((fptr = foo_alloc()) == NULL)
		err_sys("foo_alloc error");

	for (i = 0; i < THREADNUM; ++i) {
		err = pthread_create(&tid, NULL, thr_fn, NULL);

		if (err != 0)
			err_quit("can't create thread: %s\n", strerror(err));

		printf("new thread %ld\n", tid);
	}

	tid = pthread_self();
	printf("main thread %ld\n", tid);

	/* makes the main thread equal to others */
	thr_fn(NULL);

	while(fptr != NULL)
		sleep(1);

	return 0;
}
Пример #3
0
int
main(void)
{
  int i, err;
  void *tret;
  pthread_t tids[LENGTH];
  struct foo *fp;

  fp = foo_alloc();

  for (i=0; i<LENGTH; i++) {
    if ((err = pthread_create(tids+i, NULL, thr_fn, (void *) fp)) != 0)
      continue;
  }

  for (i=0; i<LENGTH; i++) {
    if ((err = pthread_join(tids[i], &tret)) != 0)
      continue;
  }

  printf("count = %d\n", fp->f_count);

  foo_rele(fp);
  exit(0);
}
Пример #4
0
int main(void)
{
	fptr = foo_alloc();
	if(fptr==NULL)
		err_quit("can not allocate foo struct\n");

	pthread_t tid1,tid2;
	tid1 = pthread_create(&tid1,NULL,thr_fn,NULL);
	tid2 = pthread_create(&tid2,NULL,thr_fn,NULL);
	
	sleep(10);
	return 0;
}
Пример #5
0
int main(){
	mutexfoo *fp = foo_alloc(12345);
	pthread_t tid1,tid2;

	if(pthread_create(&tid1,NULL,thread_fun1,fp)!=0)
		err_sys("create pthread is error \n");
	if(pthread_create(&tid2,NULL,thread_fun2,fp)!=0)
			err_sys("create pthread is error \n");
	printf("main pthread is sleep \n");
	sleep(10);
	printf("main pthread is wake up \n");
	exit(1);
}
Пример #6
0
void main()
{
    int i,err;
    unsigned int ntid;
    //Intial our hash
    for(i=0;i<NHASH;++i)
	fh[i]=NULL;
    m_fp=foo_alloc();
    for(i=0;i<5;++i){
	err=pthread_create((pthread_t *)(&ntid),NULL,thr_fn,NULL);
	if(err!=0)
	    err_quit("can't create thread:%s \n",strerror(err));
    }
    sleep(5);
    while(m_fp!=NULL){
	printf("usage count: %d\n",m_fp->f_count);
	foo_rele(m_fp);
    }
    printf("usage count: 0\n");
    sleep(10);
}
int main(void)
{
    pthread_t tid1, tid2;
    int err;
    void *ret;
    struct foo *obj;
    obj = foo_alloc();

    err = pthread_create(&tid1, NULL, thread_fun1, (void*)obj);
    if(err != 0)
        err_quit("pthread_create error: %s\n", strerror(err));

    err = pthread_create(&tid2, NULL, thread_fun2, (void*)obj);
    if(err != 0)
        err_quit("pthread_create error: %s\n", strerror(err));

    pthread_join(tid1, &ret);
    printf("thread 1 exit code is: %d\n", (int)ret);
    pthread_join(tid2, &ret);
    printf("thread 2 exit code is: %d\n", (int)ret);

    exit(0);
}
Пример #8
0
void main()
{
    struct foo *test;
    test = foo_alloc();    
    foo_rele(test);
}