上海东方cj的电话号码:抛砖引玉.......

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/18 21:56:16
那天答应给:“人才0252”的多线程的一个例子
由于LINUX服务器坏掉了没有拷出来,今天修好
了补上,请各位点评!

---------------------------------------
头文件
---------------------------------------
/*
* Data struct
*/
#ifndef _8Q_H
#define _8Q_H

#include <stdio.h>
#include <pthread.h>
#include <errno.h>

#define QUEEN_NUM 8

int result=0; /*save result number*/
int max_num=0; /*save the number of threads which had been opened*/
int current_threads_number; /*save the number of threads which are running now*/
pthread_attr_t thread_attr; /*thread attribute*/
pthread_mutex_t mutex; /*the locker of share vary*/

struct current_board{ /*chess board struct*/
int board[QUEEN_NUM];
};

extern void _init_all(struct current_board * chess_board); /*initial function*/
extern void _create_child(struct current_board * chess_board); /*open thread function*/
extern void _child(struct current_board * chess_board); /*child thread funciton*/
extern int _test_ok(struct current_board * board); /*test if the chess place right*/

#endif /*_8Q_H*/