检索规则说明:AND代表“并且”;OR代表“或者”;NOT代表“不包含”;(注意必须大写,运算符两边需空一格)
检 索 范 例 :范例一: (K=图书馆学 OR K=情报学) AND A=范并思 范例二:J=计算机应用与软件 AND (U=C++ OR U=Basic) NOT M=Visual
作 者:申时全[1]
出 处:《微型机与应用》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[自动化与计算机技术—计算机软件与理论]
正在载入数据...
正在载入数据...
正在载入数据...
正在载入数据...
正在载入数据...
正在载入数据...
正在载入数据...
正在链接到云南高校图书馆文献保障联盟下载...
云南高校图书馆联盟文献共享服务平台 版权所有©
您的IP:216.73.216.15