/*************************************************************************** * * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved * $Id: xutils.cpp,v 1.1 2008/09/03 06:47:49 xiaowei Exp $ * **************************************************************************/ /** * @file xutils.cpp * @author xiaowei(com@baidu.com) * @date 2008/06/12 23:45:39 * @version $Revision: 1.1 $ * @brief * **/ #include #include #include int run_thread(void *(*fun)(void *), void *p, int pnum) { pthread_t *pid = new pthread_t[pnum]; for (int i=0; ipnum = tpnum; _s.tv_sec = 0; _e.tv_sec = 0; _s.tv_usec = 0; _e.tv_usec = 0; this->inp = 0; pthread_mutex_init(&lock, NULL); pthread_cond_init(&cond, NULL); } Slotime::~Slotime() { pthread_mutex_destroy(&lock); pthread_cond_destroy(&cond); } int Slotime::cost() { return XTIMEDIFF(_s, _e); } int Slotime::start() { pthread_mutex_lock(&lock); ++inp; if (inp == pnum) { for (int i=1; i