Why is len() not implemented for Queues?

The built-in function len() (https://docs.python.org/3/library/functions.html#len) returns "the length (the number of items) of an object", but this is not implemented for queue.Queue (https://docs.python.org/3/library/queue.html). Instead, queue.Que...
more »

2017-12-01 02:12 (1) Answers

Multiple threads handler vs ThreadPoolExecutor

I have some managers that execute different tasks and I need that this tasks are executed in background to keep the main Thread free. So, I'm using 3 threads and communicating them with handlers (with a main manager). I've read about the ThreadPoolEx...
more »

2017-11-29 16:11 (1) Answers

Do I need a lock if I have EventWaitHandle

Studying multi-threading from albahari atricle. Do I need a lock _locker in the sample below? I suppose no, since _message is protected by EventWaitHandle. Am I right? class TwoWaySignaling { static EventWaitHandle _ready = new AutoResetEvent (f...
more »

2017-11-27 10:11 (2) Answers

Why isn't the last thread interrupted?

I am trying to demonstrate an "anytime algorithm" - an algorithm that can be stopped at any time and returns its current result. The demo algorithm just returns some mathematical function of i, where i is increasing. It chcecks whether it is interrup...
more »

2017-11-26 21:11 (1) Answers

Java parallel stream internals

I noticed that depends of implementation of doSth() method (if thread sleeps for a constant or random amount of time) a parallel stream is being executed differently. Example: import java.util.Random; import java.util.concurrent.ExecutionException;...
more »

2017-11-26 20:11 (2) Answers

ReentrantLock fairness parameter

This question is full theoretical, I'm sorry but I cannot avoid this time. I'm learning about ReentrantLock and read this: Note however, that fairness of locks does not guarantee fairness of thread scheduling. What does this mean? How can I ima...
more »

2017-11-24 13:11 (1) Answers

C# SQL connection OpenAsync is not asynchronous

I'm trying to open a connection to an SQL server asynchronously, so as not to tie up the UI thread. But I've found that the call to connection.OpenAsync() does not return until the connection has been opened, exactly as with connection.Open(). This ...
more »

2017-11-23 14:11 (2) Answers

Is a Jersey Client WebTarget thread-safe?

Is a Jersey Client WebTarget created as following thread-safe? WebTarget client = ClientBuilder .newClient(new ClientConfig(new JacksonJaxbJsonProvider(<object mapper Jackson>, JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS))) .ta...
more »

2017-11-18 21:11 (1) Answers

Multi Threading Shared Local Variables

I am trying to fully understand how creating separate threads that call the same method of a class instance can effect local variables in the method. For example I have a class with a single method (Divide) public class Maths { public int Num1;...
more »

2017-11-18 13:11 (2) Answers

is it possible for `ConcurrentHashMap` to hang?

First I'll summarize what I've found so far. This answer suggests that changing the concurrencyLevel parameter of ConcurrentHashMap's constructor might help. I've tried that and my code still hanged. Answers here suggest that it could be a runtime ...
more »

2017-11-17 04:11 (2) Answers

Error in malloc while trying to create a thread

Hi everyone i post only the core of the code which create probleam and which work with threads. #define HR_OFF h_r-1 pthread_t *threads = NULL; int h_r = 1; int foo(int handler) { // if everything is empty alloc resources if (threads == NULL...
more »

2017-11-13 19:11 (1) Answers

ActiveX DLL clogs up main UI thread

I'm struggling with running a function from an ActiveX DLL (compiled from VB6) in a background thread from a C# WinForms application. Because the VB6 DLL project contains a lot of references to an old library called Sheridan Controls (threed32.ocx)...
more »

2017-11-13 13:11 (1) Answers

C# Singleton Pattern Designs for ThreadStatic

I want to figure out about singleton pattern designs. I want to create seperated instances for per thread from my singleton class. So I provided two designs below. It is Working class Program { static void Main(string[] args) { Task...
more »

2017-11-11 15:11 (2) Answers

CoreText crashed when run in multiple threads

Crashed when I calculate layout in multiple threads . I've looked up the answers but there are mostly out of date . They said that there is Apple's CoreText bug , and has been fixed . But crashed models include iPhone6、iPhone6s、iPhone7、iPhone8
more »

2017-11-09 07:11 (0) Answers

SpriteKit, put a process on another core?

Imagine in your class NattyScene: SKScene { you have perhaps a custom Field for the nodes, or something else that happens every frame. Now imagine you have some calculation, a nice example might be center of gravity ... var globalCOG: CGPoint fu...
more »

2017-11-09 00:11 (1) Answers

Invoking a method's result to the main thread

I am wondering about the following: I have an observable collection named Container and method named Method. On the main thread I want to add the returned value from Method to the Container. The following code runs on another thread, so I have to ...
more »

2017-11-03 08:11 (2) Answers

Happens-before for direct ByteBuffer

I have a direct ByteBuffer (off-heap) in one thread and safely publish it to a different thread using one of the mechanisms given to me by JMM. Does the happens-before relationship extend to the native (off-heap) memory wrapped by the ByteBuffer? If ...
more »

2017-11-01 09:11 (2) Answers