上一页 1 2 3 4 5 6 7 8 9 10 ··· 21 下一页
摘要: 插入排序: 1 #include 2 #include 3 #include 4 5 int arry[7] = {49,38,65,97,76,13,27}; 6 7 void show_arry() 8 { 9 int i;10 for(i = 0; i 0 && tmp < arry[j - 1]){23 arry[j] = arry[j - 1];24 arry[j - 1] = tmp;25 j--; 26 }27 } 28 }29 30 void te... 阅读全文
posted @ 2013-10-30 17:21 net小伙 阅读(309) 评论(0) 推荐(0) 编辑
摘要: 直接上代码: 1 #include 2 #include 3 4 struct val{ 5 int num1; 6 int num2; 7 }; 8 9 //send a int to arg10 void *text(void *arg)11 {12 int *p = (int *)arg;13 printf("arg is %d\n",*p);14 pthread_exit(NULL);15 }16 17 //send char to arg18 void *text2(void *arg)19 {20 char *d = (cha... 阅读全文
posted @ 2013-10-27 22:46 net小伙 阅读(9962) 评论(0) 推荐(0) 编辑
摘要: 函数名pthread_mutex_lock, pthread_mutex_trylock, pthread_mutex_unlock - lock and unlock a mutexSYNOPSIS概要#include int pthread_mutex_lock(pthread_mutex_t *mutex);int pthread_mutex_trylock(pthread_mutex_t *mutex);int pthread_mutex_unlock(pthread_mutex_t *mutex);描述pthread_mutex_lock()函数锁住由mutex指定的mutex对象。 阅读全文
posted @ 2013-10-25 21:13 net小伙 阅读(2162) 评论(0) 推荐(0) 编辑
摘要: 1、引入pthread_equal的原因:在线程中,线程ID的类型是pthread_t类型,由于在Linux下线程采用POSIX标准,所以,在不同的系统下,pthread_t的类型是不同的,比如在ubuntn下,是unsigned long类型,而在solaris系统中,是unsigned int类型。而在FreeBSD上才用的是结构题指针。所以不能直接使用==判读,而应该使用pthread_equal来判断。2、引入pthread_self的原因: 在使用pthread_create(pthread_t *thread_id,NULL,void* (*fun) (void *),void * 阅读全文
posted @ 2013-10-24 21:07 net小伙 阅读(1488) 评论(0) 推荐(0) 编辑
摘要: 1 #include2 int sigsuspend(const sigset_t *sigmask);3 返回值:-1,并将errno设置为EINTR 将进程的信号屏蔽字设置为由sigmask指向的值,在捕捉到一个信号或发生了一个会终止该进程的信号之前,该进程被挂起。例子: 利用sigsuspend函数阻塞子进程; 1 #include 2 #include 3 #include 4 #include 5 6 sig_atomic_t sigflag; 7 sigset_t newmask,oldmask,zeromask; 8 9 void sig_int(... 阅读全文
posted @ 2013-10-21 16:56 net小伙 阅读(1107) 评论(0) 推荐(0) 编辑
摘要: 1、有时候不希望在接到信号时就立即停止当前执行,去处理信号,同时也不希望忽略该信号,而是延时一段时间去调用信号处理函数。这种情况是通过阻塞信号实现的。2、信号阻塞和忽略信号的区别。阻塞的概念和忽略信号是不同的。操作系统在信号被进程解除阻塞之前不会讲信号传递出去,被阻塞的信号也不会影响进程的行为,信号只是暂时被阻止传递。当进程忽略一个信号时,信号会被传递出去但进程会将信号丢弃。3、信号阻塞系统调用,它们的都起到阻塞的作用,它们不是协作使用的。[cpp]view plaincopyprint?#includeintsigprocmask(ubthow,constsigset_t*set,sigse 阅读全文
posted @ 2013-10-19 11:08 net小伙 阅读(1423) 评论(0) 推荐(0) 编辑
摘要: 1 #include2 3 int setjmp(jmp_buf env);4 返回值:若直接调用则返回0,若从longjmp调用返回则返回非0值5 6 void longjmp(jmp_buf env, int val); 在希望返回的位置调用setjmp,直接调用该函数返回值为0;参数env的类型是一个特殊类型jmp_buf。这一数据类型是某种形式的数组,其中存放在调用longjmp时能用来恢复栈状态的所有信息。 longjmp的两个参数,第一个是在调用setjmp时所用的env;第二个参数是具有非零值的val,它将成为从setjmp处返回的值。使用第二个参数的原因是对于一个s... 阅读全文
posted @ 2013-10-10 16:09 net小伙 阅读(332) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 3 int main() 4 { 5 int a[5] = {3,5,6,1,4}; 6 int b[5] = {1,9,12,4,3}; 7 int c[10]; 8 9 int i,j = 0;10 int k;11 int tmp;12 int flag;13 14 //合并ab到c15 for(i = 0; i c[k])29 j = k;30 }31 32 if(j != i){33 tmp ... 阅读全文
posted @ 2013-10-09 09:37 net小伙 阅读(736) 评论(0) 推荐(0) 编辑
摘要: 下面设置了一个长度为20的缓存区,循环对value进行赋值并输出; 1 #include 2 3 #define BUFSIZE 20 4 5 int main(int argc, char *argv[]) 6 { 7 char value[5]; 8 char buf[BUFSIZE]; 9 10 setvbuf(stdin,buf,_IOFBF,20);11 12 while(scanf("%s",value), value != NULL){13 puts(value);14 }1... 阅读全文
posted @ 2013-10-04 15:07 net小伙 阅读(1743) 评论(0) 推荐(0) 编辑
摘要: 递归降序遍历目录层次结构,并按文件类型计数。 先介绍相关的函数:#includeDIR *opendir(const char *pathname); //打开目录返回值:成功返回指针,出错返回NULLstruct dirent *readdir(DIR *dp); //读取目录 返回值:成功返回指针,出错返回NULLvoid rewinddir(DIR *dp); //重设读取目录的位置为开头位置int closedir(DIR *dp); ... 阅读全文
posted @ 2013-10-02 18:16 net小伙 阅读(509) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 10 ··· 21 下一页