在实现线程的过程中,我们经常会写类似于这样的代码:{ mutex_.lock(); //XXX if(...) 语句; //XXX mutex_.unlock();}虽然这段代码是正常的加锁解锁,但是有时候我们难免会出现一些低级错误,例如把 忘了写...
分类:
系统相关 时间:
2014-10-08 04:01:04
阅读次数:
379
我们不止一次写过这种代码: { mutex_.lock(); //XXX if(....) return; //XXX mutex_.unlock();
} 显然,这段代码中我们忘记了解锁。那么如何防止这种情况,我们采用和智能指针相同的策略,把加锁和解锁的过程封装在一个对象中。 实现“对象生命期”等...
分类:
系统相关 时间:
2014-10-07 21:53:24
阅读次数:
215
本文对pthread_mutex_t 进行简易的封装;互斥锁主要用于互斥,描述的是一种竞争关系,主要是一个 一种资源或者代码, 在一段时间内 至多能被一个程序访问。而条件变量主要用于线程间同步, 描述的是一种协作关系。Linux中互斥锁的应用比较简单,通用的有以下几个函数:1 int pthread...
分类:
系统相关 时间:
2014-10-06 22:44:20
阅读次数:
241
本文对Linux中的pthread_mutex_t做一个简易的封装。 互斥锁主要用于互斥,互斥是一种竞争关系,主要是某一个系统资源或一段代码,一次做多被一个线程访问。 条件变量主要用于同步,用于协调线程之间的关系,是一种合作关系。 Linux中互斥锁的用法很简单,最常用的是以下的几个函数: int ...
分类:
系统相关 时间:
2014-10-06 18:47:20
阅读次数:
188
构造数据: > dataset = matrix(c(1,2,
+ 1.2,2,
+ 8,9,
+ 0.9,1.8,
+ 7,10,
+ 8.8,9.2), nrow=6, byrow=T)
> dataset
[,1] [,2]
[1,] 1.0 2.0
[2,] 1.2 2.0
[3,] 8.0 9.0
[4,] 0.9 1.8
[5,] 7.0 1...
分类:
其他好文 时间:
2014-10-05 15:27:28
阅读次数:
373
APUE 线程 - 程序清单
程序清单11-1 打印线程ID
程序清单11-2 获得线程退出状态
程序清单11-3 pthread_exit 的参数不正确使用
程序清单11-4 线程清理处理程序
程序清单11-5 使用互斥量保护数据结构
程序清单11-6 使用两个互斥量
程序清单11-7 简化的加,解锁
程...
分类:
编程语言 时间:
2014-10-05 01:31:37
阅读次数:
191
linux下的同步和互斥
Linux sync_mutex
Semaphore.h
一份好文档,胜读十年书
本文参考了诸多资料,百度百科,cplusplus等
首先介绍一个头文件
#include
这里面包含了大多数的所需要使用的信号量.
包含:
int sem_init(sem_t *sem, int pshared, unsigned int value)...
分类:
系统相关 时间:
2014-10-03 23:39:55
阅读次数:
378
This paper provides an overview and some conclusions from the HOUSING datasets disposed by the classical algorithms Kmeans and Hierarchical clustering. The total process of the project is divided into five parts including data preprocessing, selecting the ...
分类:
其他好文 时间:
2014-10-03 13:14:24
阅读次数:
141
package?main?
import?(
"fmt"
"sync"
"runtime"
)
var?counter?int?=?0
func?Count(lock?*sync.Mutex)?{
lock.Lock()
counter++
fmt.Println(counter)
lock.Unlock()
}
func?main()?{
lo...
分类:
其他好文 时间:
2014-10-01 00:32:30
阅读次数:
389
MainActivity.java
package com.apress.threads;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;...
分类:
移动开发 时间:
2014-09-28 20:43:45
阅读次数:
224