coroutine

Fast fibers/coroutines under x64 Windows

人走茶凉 提交于 2020-01-01 18:17:33
问题 So I have this coroutine API, extended by me, based on code I found here: https://the8bitpimp.wordpress.com/2014/10/21/coroutines-x64-and-visual-studio/ struct mcontext { U64 regs[8]; U64 stack_pointer; U64 return_address; U64 coroutine_return_address; }; struct costate { struct mcontext callee; struct mcontext caller; U32 state; }; void coprepare(struct costate **token, void *stack, U64 stack_size, cofunc_t func); /* C code */ void coenter(struct costate *token, void *arg); /* ASM code */

Dynamically add to list of what Python asyncio's event loop should execute

烂漫一生 提交于 2020-01-01 04:43:05
问题 I've got a function download_all that iterates through a hardcoded list of pages to download them all in sequence. But if I'd like to dynamically add to the list based on the results of a page, how can I do it? For example download the first page, parse it, and based on the results add others to the event loop. @asyncio.coroutine def download_all(): first_page = 1 last_page = 100 download_list = [download(page_number) for page_number in range(first_page, last_page)] gen = asyncio.wait

深入Golang调度器之GMP模型

喜夏-厌秋 提交于 2019-12-29 18:04:13
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 前言 随着服务器硬件迭代升级,配置也越来越高。为充分利用服务器资源,并发编程也变的越来越重要。在开始之前,需要了解一下并发(concurrency)和并行(parallesim)的区别。 并发 : 逻辑上具有处理多个同时性任务的能力。 并行 : 物理上同一时刻执行多个并发任务。 通常所说的并发编程,也就是说它允许多个任务同时执行,但实际上并不一定在同一时刻被执行。在单核处理器上,通过多线程共享CPU时间片串行执行(并发非并行)。而并行则依赖于多核处理器等物理资源,让多个任务可以实现并行执行(并发且并行)。 多线程或多进程是并行的基本条件,但单线程也可以用协程(coroutine)做到并发。简单将Goroutine归纳为协程并不合适,因为它运行时会创建多个线程来执行并发任务,且任务单元可被调度到其它线程执行。这更像是多线程和协程的结合体,能最大限度提升执行效率,发挥多核处理器能力。 Go编写一个并发编程程序很简单,只需要在函数之前使用一个Go关键字就可以实现并发编程。 作者:云爬虫技术研究笔记 链接:https://www.jianshu.com/p/abe79d86ff27 来源:简书 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 来源: oschina 链接: https://my

Wait for a coroutine to finish before moving on with the function C# Unity

依然范特西╮ 提交于 2019-12-28 06:59:11
问题 I was working on making a unit move through a grid in Unity2d. I got the movement to work without problems. I would want the function MovePlayer to wait until the coroutine is finished before moving on, so the program will wait until the player has finished the movement before issuing more orders. Here is my code: public class Player : MonoBehaviour { public Vector3 position; private Vector3 targetPosition; private float speed; void Awake () { speed = 2.0f; position = gameObject.transform

Unity stop and start coroutines

馋奶兔 提交于 2019-12-25 08:59:38
问题 How can I have a function which will play a coroutine, but first check if it is already running to stop it if it is? EDIT : Sorry I didnt see that someone had already asked/answered this and it was something I was stuck on for a bit 回答1: public class Example : MonoBehaviour { [SerializeField] // Allow the variable to be edited in editor private float parameterValue; private IEnumerator coroutine; private IEnumerator CoroutineA(float _parameter) { // do something, usually for _parameter time }

Unity coroutine not running to the end

女生的网名这么多〃 提交于 2019-12-25 08:44:06
问题 I am having a weird problem with a coroutine. Basically when I mouse over a sprite it fades in and out as long as the mouse pointer is over it, this works fine, but when the mouse exits the sprite I want the sprite to fade out until its alpha value reaches 0. To do so and because unlike the OnMouseOver function which is called every frame while the mouse is over the collider, I use a coroutine called in my OnMouseExit function. The code below is what I use, but as soon as the mouse exits the

Refer to one of many coroutines in Unity3D?

…衆ロ難τιáo~ 提交于 2019-12-24 13:58:01
问题 Is there a way to have a variable point to one of a number of coroutines in C# in Unity3D? public class Example : MonoBehaviour { ? something ? crt; private IEnumerator CoroutineA() { } private IEnumerator CoroutineB() { } void Start() { crt = CoroutineA; StartCoroutine(crt); } } 回答1: The type that you are looking for is a delegate. Delegates are similar to function pointers, and are not specific to Unity3D. public class Example : MonoBehaviour { private delegate IEnumerator CoroutineDelegate

Delay() accuracy issues / Weird behavior of job scheduler

本秂侑毒 提交于 2019-12-24 10:56:31
问题 I'm currently trying to build a job scheduler as shown below. My goal is to be able to schedule the launch of arbitrary functions (here of (Long) -> Unit)) with as much accuracy as possible on their launch time (sub-millisecond would be ideal). import java.util.* import kotlinx.coroutines.* import java.util.concurrent.PriorityBlockingQueue import kotlin.math.max import java.time.Instant fun nowInMicrosSinceEpoch() : Long { val now = Instant.now() return now.toEpochMilli() * 1000L + (now

Unity Coroutine not working across scenes

三世轮回 提交于 2019-12-24 04:31:40
问题 I am calling a Coroutine shown below, which is attached to a DontDestroyOnLoad objects that persists across scenes. IEnumerator InitMaxScore() { Debug.Log("will wait for some time"); yield return new WaitForSeconds(1); GameObject[] coins = GameObject.FindGameObjectsWithTag("Coin"); Debug.Log("coins length == " + coins.Length); if (coins.Length > 0) { maxScoreInitialized = true; maxScore = score + coins.Length * 10; foreach (GameObject healthPickup in GameObject.FindGameObjectsWithTag("Health"

Recreate job after another job is completed

落爺英雄遲暮 提交于 2019-12-23 16:14:10
问题 I have the following situation: job1 and job2 go to the server in the same time and both of them came back with status 401 , which means that my token access has expired and I need to make a refresh. I start job3 which came back the new token. In this case, I have to recreate the job1 and job2 with the new token on request and start them. I have a jobDispatcher, but it seems that it not help me in situation. Here it is : class JobDispatcher : CoroutineDispatcher() { private val queue: Queue