concurrency

Is it enough to declare a function as transaction_safe, so they can be used thread-safe?

十年热恋 提交于 2019-12-23 02:39:13
问题 Is enough just to declare all of the functions as transaction_safe in some my class, so its can be used as thread-safe in transactions atomic_noexcept, atomic_cancel, atomic_commit from Experimental Transactional Memory TS? As known there are Transactional Memory TS (ISO/IEC TS 19841:2015) in the Experimental C++ standard libraries. Simple examples are here: http://en.cppreference.com/w/cpp/language/transactional_memory Also there is Technical Specification for C++ Extensions for

Netty Comet Async request time out

折月煮酒 提交于 2019-12-23 02:19:00
问题 I'm trying to create long polling Comet using Jboss Netty. How can I configure time out of 30 sec? Following the documentaton: @Override public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("decoder", new HttpRequestDecoder()); pipeline.addLast("encoder", new HttpResponseEncoder()); pipeline.addLast("handler", new HTTPRequestHandler()); Timer timer = new HashedWheelTimer(); pipeline.addLast("timeout", new IdleStateHandler

Possible concurrency issue in Xlet development

主宰稳场 提交于 2019-12-23 02:17:31
问题 I am involved in development of Xlet using Java 1.4 API. The docs say Xlet interface methods (those are actually xlet life-cycle methods) are called on its special thread (not the EDT thread). I checked by logging - this is true. This is a bit surprising for me, because it is different from BB/Android frameworks where life-cycle methods are called on the EDT, but it's OK so far. In the project code I see the app extensively uses Display.getInstance().callSerially(Runnable task) calls (this is

How can I safely decorate an existing callback?

核能气质少年 提交于 2019-12-23 02:16:09
问题 Suppose I'm working with the following callback API: /** * Registers a new action which will be run at some later time on * some other thread, clearing any previously set callback action. * * @param callback an action to be run later. * @returns the previously registered action. */ public Runnable register(Runnable callback); I'd like to register my own action, but I want to preserve any set behavior. In other words I'd like my action to look something like: new Runnable() { public void run()

Can I use a ProcessPoolExecutor from within a Future?

微笑、不失礼 提交于 2019-12-23 02:15:11
问题 I have a program that takes in a list. For each value in this list, it retrieves another list and processes this other list. Basically, it's a 3-depth tree which need to do possibly expensive processing at each node. Each nodes needs to be able to process the results of its children. What I'd like to be able to do is to map from the inputs in the first layer list to the results of each node. In each of these processes though, I would like to map the result from the next layer down. What I'm

Strictly auto-increment value in MySQL

你离开我真会死。 提交于 2019-12-23 02:01:49
问题 I have to create a MySQL InnoDB table using a strictly sequential ID to each element in the table (row). There cannot be any gap in the IDs - each element has to have a different ID and they HAVE TO be sequentially assigned. Concurrent users create data on this table. I have experienced MySQL "auto-increment" behaviour where if a transaction fails, the PK number is not used, leaving a gap. I have read online complicated solutions that did not convince me and some other that dont really

GCD implementation on a UITableView

陌路散爱 提交于 2019-12-23 01:45:16
问题 I am doing some heavy calculations when I am creating cells. I am trying to figure out the best way to keep the UITableView fluid, but at the same type do the calculations on the background (keep the UI thread without too much processing). For testing purposes only, I am using this as my heavy calculation method: +(NSString*)bigCalculation { int finalValue=0; int j=0; int i=0; for (i=0; i<1000; i++) { for (j=0; j<10000000; j++) { j++; } finalValue+=j/100*i; } return [NSString stringWithFormat

Why doesn't concurrent.futures.ThreadPoolExecutor().submit return immediately?

元气小坏坏 提交于 2019-12-22 19:45:12
问题 In this code: import concurrent.futures import time def pafter(t): time.sleep(t) print('Hi') with concurrent.futures.ThreadPoolExecutor(5) as e: e.submit(pafter, 2) print('With returned') I expect to see: With returned Hi but I see: Hi With returned Why doesn't submit return immediately? What do I change to make it do so? 回答1: Using the with statement is equivalent to calling executor.shutdown() , which is documented like this: shutdown(wait=True) Signal the executor that it should free any

Why doesn't concurrent.futures.ThreadPoolExecutor().submit return immediately?

旧巷老猫 提交于 2019-12-22 19:45:11
问题 In this code: import concurrent.futures import time def pafter(t): time.sleep(t) print('Hi') with concurrent.futures.ThreadPoolExecutor(5) as e: e.submit(pafter, 2) print('With returned') I expect to see: With returned Hi but I see: Hi With returned Why doesn't submit return immediately? What do I change to make it do so? 回答1: Using the with statement is equivalent to calling executor.shutdown() , which is documented like this: shutdown(wait=True) Signal the executor that it should free any

How to test unlikely concurrent scenarios?

筅森魡賤 提交于 2019-12-22 19:32:32
问题 For example, map access like this: func (pool *fPool) fetch(url string) *ResultPromise { pool.cacheLock.RLock() if rp, pres := pool.cache[url]; pres { pool.cacheLock.RUnlock() return rp } pool.cacheLock.RUnlock() pool.cacheLock.Lock() if rp, pres := pool.cache[url]; pres { pool.cacheLock.Unlock() // Skip adding url if someone snuck it in between RUnlock an Lock return rp } rp := newPromise() pool.cache[url] = rp pool.cacheLock.Unlock() pool.c <- fetchWork{rp, url} return rp } Here, the