自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

you are sherlocked by me!

大家好,我是江湖狗哥!

  • 博客(13)
  • 收藏
  • 关注

原创 python threading.Event

线程同步的方式 (保证线程安全) 互斥量(锁): 通过互斥机制防止多个线程同时访问公共资源 信号量(semaphore): 控制同一时刻多个线程访问同一个资源的线程数 事件(signal): 通过通知的方式保持多个线程同步 事件(信号) Event是最简单的线程间通信机制,一个线程负责给事件发信号,其他线程等待事件。 Event类内部有一个flag标识,初始值为False。 Event类...

2019-11-17 22:08:52 422

原创 Python信号量threading.Semaphore

信号量主要用在保护有限的资源。 以数据库连接数为例说明,假设当前数据库支持最大连接数为3, 将信号量初始值设为3,那么同时最大可能有三个线程连接数据库,其他线程若再想连接数据库,则只有等待,直到某一个线程释放数据库连接 #!usr/bin/python # -*- coding:utf8 -*- import time import threading sm = threading.Sema...

2019-11-17 21:12:16 699

转载 并发编程之缓存一致性

并发编程之缓存一致性 Java内存模型(JMM)的设计是建立在物理机的内存模型之上的,因此了解物理机内存模型的原理也十分重要。简单来说,物理机的内存模型经历了3个阶段: 早期的CPU计算速率与内存操作速率相当,CPU直接从内存中读取数据,运行程序计算,得出结果再写入内存; 后来CPU飞速发展,内存的速率已经远不及CPU的计算了,这时CPU计算任务因等待内存数据读取而停滞,造成计算资源浪费,于是人们...

2019-11-17 19:15:56 359

转载 为什么volatile关键字保证不了线程安全

对于缓存一致性和线程安全之间的联系还有点蒙,找了一篇博文看 在当前高并发的时代,不懂一点高并发多线程都不好意思出去,即使没地方使用,网上大多数相关文档博客也都讲解了这些部分。 我并不想具体介绍什么是volatile,我写这篇博客目的是说明白为什么volatile保证不了线程安全。想要线程安全必须保证原子性,可见性,有序性。而volatile只能保证可见性和有序性 在说明这个问题之前,首先还是...

2019-11-17 18:55:58 402

原创 回文数判断(Leetcode)

problem address Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. Example 1: Input: 121 Output: true Example 2: Input: -121 Outp...

2019-11-01 20:09:38 313

原创 反转字符串(Leetcode)

problem address Write a function that reverses a string. The input string is given as an array of characters char[]. Do not allocate extra space for another array, you must do this by modifying the...

2019-11-01 19:39:48 190

原创 合并k个有序链表(Leetcode)

problem address Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example: Input: [ 1->4->5, 1->3->4, 2->6 ] Output: 1->1-&...

2019-11-01 19:36:36 189

原创 用栈实现队列(Leetcode)

problem address Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of queue. pop() -- Removes the element from in front of queue. peek() -- Get the fr...

2019-11-01 19:32:08 248

原创 层序遍历二叉树(Leetcode)

problem address Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example: Given binary tree [3,9,20,null,null,15,7], 3 ...

2019-11-01 19:26:10 252

原创 合并两个有序链表(Leetcode)

problem address Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. Example: Input: 1->2->4, 1->3...

2019-11-01 19:21:46 175

原创 删除一个链表节点(Leetcode)

problem address Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Given linked list -- head = [4,5,1,9], which looks like following: ...

2019-11-01 19:16:39 201

原创 二叉树镜像(Leetcode)

Invert a binary tree. Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia: This problem was inspired by this original t...

2019-11-01 19:05:41 349

原创 Python中的is和==区别

预先知识 Python的字典和集合底层都是哈希表实现的,哈希表存在两个问题: 1. 哈希冲突的解决方法和根据装载因子扩容问题 在Java中HashMap的实现方式是扩容容量增加为原来两倍,解决冲突的方法是链地址法, 当某个箱子的链表长度>8,转化为红黑树, <6,从红黑树转换为链表,以便提高插入删除查询的性能 如果两个对象相同,hashcode一定相同。但是hashcode相同的两...

2019-11-01 16:49:44 191

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除