c# TPL中的数据竞争-Data Race
例一: Parallel.For(1, arraySize, i =>
{
ary[i] = ary[i] + ary[i - 1];
});
如下:
object _lock = new object();
Parallel.For(1, arraySize, i =>
{
lock(_lock)
ary[i] = ary[i] + ary[i - 1];
});
解决方案:lock 确保当一个线程位于代码的临界区时,另一个线程不进入临界区,如果其他线程试图进入锁定的代码,则它将一直等待,直到该对象被释放
例二:
private static readonly AsyncLocal<LocalLifeTineScopelrapper> AsynclLocallLifeScope = new AsyncLocal<LocalLifeTimeScopelrapper>(); private static ILifetimeScope GetCurrentUow()
{
var uow = AsyncLocalLifeScope.Value ? .LifetimeScope;
if(uow == null)
{
return null;
}
return uow;
}
解决如下
private static ILifetimeScope GetCurrentUow()
{
lock(AsynclLocallLifeScope)
{
var uow = AsyncLocalLifeScope.Value ? .LifetimeScope;
if(uow == null)
{
return null;
}
return uow;
}
}
c# TPL中的数据竞争-Data Race的更多相关文章
- Oracle中读取数据一些原理研究
文章很多摘录了 http://blog.163.com/liaoxiangui@126/blog/static/7956964020131069843572/ 同时基于这篇文章的基础上,补充一些学习要 ...
- 在Salesforce中通过dataloadercliq调用data loader来批量处理数据
上一篇文章讲到,通过data loader去批量处理数据,那么这篇文章将主要讲解在Salesforce中通过dataloadercliq调用data loader来批量处理数据. 1): CLIq文件 ...
- [MySQL]load data local infile向MySQL数据库中导入数据时,无法导入和字段不分离问题。
利用load data将文件中的数据导入数据库表中的时候,遇到了两个问题. 首先是load data命令无法执行的问题: 命令行下输入load data local infile "path ...
- Web网页中动态数据区域的识别与抽取 Dynamical Data Regions Identification and Extraction in Web Pages
Web网页中动态数据区域的识别与抽取 Dynamical Data Regions Identification and Extraction in Web Pages Web网页中动态数据区域的识别 ...
- load data导txt文件进mysql中的数据
1.实验内容: 利用SQL语句“load data ”将“.txt”文本文件中的数据导入到mysql中 2.实验过程: 首先我创了一个txt(也可以是其他的),设置其编码为utf-8,在windows ...
- vue 需求 data中的数据之间的调用
我遇到过这种情况 就是在我的data中 会有数据调用data中的其他数据 如图 我的alertInfoType需要拿到screeningCondition中type的值 用过vue的都知道 我是不 ...
- jquery在元素中存储数据:data()
转自:http://www.php.cn/js-tutorial-405445.html 在元素中存储数据:data() 1 2 3 4 5 6 7 8 9 10 <!DOCTYPE html& ...
- 28 Data Race Detector 数据种类探测器:数据种类探测器手册
Data Race Detector 数据种类探测器:数据种类探测器手册 Introduction Usage Report Format Options Excluding Tests How To ...
- 在小程序中修改上一个页面里data中的数据调用上一个页面的方法
//获取已经打开的页面的数组 var pages = getCurrentPages(); //获取上一个页面的所有的方法和data中的数据 var lastpage = pages[pages.l ...
- Vue 在beaforeCreate时获取data中的数据
众所周知,vue在beforecreate时期是获取不到data中的 数据的 但是通过一些方法可以实现在beforecreate时获取到data中的数据 暂时想到两种放发可以实现,vue在before ...
随机推荐
- JavaWeb 之 Http
0x01:为什么会有Http? 在 HTTP 建立之初,主要目的就是为了将超文本标记语言(HTML)文档从Web服务器传送到客户端的浏览器 0x02:什么是Http? http是一个简单的,请求-响应 ...
- VUE学习-过滤器
过滤器 常用于 过滤数据 或者 格式化数据 <div class="main-container"> <div class="datetime-wrap ...
- transformers 之Trainer对应的数据加载
基础信息说明 本文以Seq2SeqTrainer作为实例,来讨论其模型训练时的数据加载方式 预训练模型:opus-mt-en-zh 数据集:本地数据集 任务:en-zh 机器翻译 数据加载 Train ...
- 关于tensor2tensor与tensorflow版本冲突的解决方案
工作需要,研究了几天的t2t,万万没想到在虚拟环境的搭建方面出现了问题. 直接安装t2t,当前是1.15.7版本,默认会安装tensorflow的最新版本,最终会在执行t2t-trainer命令的时候 ...
- PGSQL新建临时表
初始化临时表,会话结束后自动删除 普通写法 CREATE TEMP TABLE tmp_student( id VARCHAR(10), name VARCHAR(3O), age INTEGER ) ...
- CentOS 7.9 环境下构建 Python 3.9
sudo yum -y update sudo yum -y install yum-utils sudo yum-builddep -y python3 curl -O https://www.py ...
- CCIE DC Multicast Part 4.
Hi Guys, Part 4 of my CCIE DC multicast article is presented below, in this article we are going to ...
- springcloud day01
单体架构:业务所有功能都在一个项目中开发,打成一个包部署 优点是架构简单 部署成本低 缺点是 耦合度高 分布式架构:根据业务功能对系统做拆分,每个业务功能模块作为一个独立的项目开发,也称为一个服务 优 ...
- 第十章用Python获取sqlite、MySQL、Excel、csv、json中的数据
目录 获取sqlite3中的数据 sqlite3库获取sqlite数据 pandas库获取sqlite数据 获取MySQL中的数据 pymsql库获取MySQL数据 pandas库获取mysql数据 ...
- Python-numpy基本用法
import numpy as np import numpy as np #导入numpy库 _version_显示版本号 show_config() 显示配置文件 print(np.__versi ...