Linux多线程编程技术在掷骰子游戏模拟程序中的应用  被引量:2

Application of Linux multi thread programming technology in the simulation program of dice game

在线阅读下载全文

作  者:申时全[1] 

机构地区:[1]广东科技学院计算机系,广东东莞523000

出  处:《微型机与应用》2016年第9期85-88,共4页Microcomputer & Its Applications

摘  要:为了模拟概率事件,针对掷骰子游戏规则,应用Linux系统下C语言多线程机制以及多个二值信号量以实现多个线程间循环同步。通过伪随机数模拟掷骰子的点数,设计并实现了一个基于多线程方式模拟4人掷骰子游戏程序,并对1 000次游戏中每个游戏者获胜的次数进行统计。可以看出,在多次游戏中,每个游戏者获胜的概率符合概率分布规律。程序运行结果表明,利用信号量可有效实现多个线程间的同步与互斥,并简化了程序结构。In order to simulate the probability events,according to the rule of dice game,the multi thread mechanism in the C language under Linux system,and the multiple two value semaphore are applied to realize cycle synchronous among multiple threads. The program simulating4 people dice game,which is based on multi thread model,is designed and implemented. Each player’s winning numbers in 1 000 rounds of the game are calculated through simulating the points of the dice with pseudo random number. As can be seen in the game,each player has similar winning probability in most cases. The results show that using semaphores can effectively achieve synchronization and mutual exclusion among multiple threads,and can simplify the program structure.

关 键 词:多线程 线程同步 随机数 掷骰子游戏程序 

分 类 号:TP311.1[自动化与计算机技术—计算机软件与理论]

 

参考文献:

正在载入数据...

 

二级参考文献:

正在载入数据...

 

耦合文献:

正在载入数据...

 

引证文献:

正在载入数据...

 

二级引证文献:

正在载入数据...

 

同被引文献:

正在载入数据...

 

相关期刊文献:

正在载入数据...

相关的主题
相关的作者对象
相关的机构对象