Linux 下C语言简单实现线程池(4)

下面是mian函数文件

/**********************************
 * @author      wallwind@yeah.net
 * @date        2012/06/13
 * Last update: 2012/06/13
 * License:    LGPL
 *
 **********************************/

#include "global.h"
#include "Thread.h"

void* task1()
 {
  printf("# Thread working: %u\n", (int)pthread_self());
  printf("  Task 1 running..\n");
 }


    /* Some arbitrary task 2 */
 void* task2(int a)
 {
  printf("# Thread working: %u\n", (int)pthread_self());
  printf("  Task 2 running..\n");
  printf("%d\n", a);
 }
int main()
{
 printf("~~~~~~~~~~~");
 thpool_t* thpool;
 int i;
 thpool = thpool_init(5);
 puts("Adding 20 tasks to threadpool");
 int a=54;
 for (i=0; i<20; i++){
  thpool_add_work(thpool, (void*)task1, NULL);
  thpool_add_work(thpool, (void*)task2, (void*)a);
 };


    puts("Will kill threadpool");
 thpool_destroy(thpool);
 
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/9f4d0d2a4e7fae1b880d046d0afc9af0.html