multithreading

Race condition occurring during use of Parallel Streams and Atomic Variables

孤人 提交于 2021-02-18 17:59:25
问题 When the following piece of code is getting executed I am getting exceptions in a random manner. byte[][] loremIpsumContentArray = new byte[64][]; for (int i = 0; i < loremIpsumContentArray.length; i++) { random.nextBytes(loremIpsumContentArray[i] = new byte[CONTENT_SIZE]); } AtomicBoolean aBoolean = new AtomicBoolean(true); List<Long> resultList = IntStream.range(0, 64* 2) .parallel() .mapToObj(i -> getResult(i, aBoolean, repositoryPath, loremIpsumContentArray )) .collect(Collectors.toList()

Delphi multi-threading file write: I/O error 32

不打扰是莪最后的温柔 提交于 2021-02-18 17:49:14
问题 I created a class for writing thread-safe log in a text file using CriticalSection . I am not an expert of CriticalSection and multi-threading programming (...and Delphi), I'm definitely doing something wrong... unit ErrorLog; interface uses Winapi.Windows, System.SysUtils; type TErrorLog = class private FTextFile : TextFile; FLock : TRTLCriticalSection; public constructor Create(const aLogFilename:string); destructor Destroy; override; procedure Write(const ErrorText: string); end;

How to update progressbar using Clock Object with Multithreading in kivy-python?

冷暖自知 提交于 2021-02-18 17:48:07
问题 I am making an app in kivy for that i am using linux. i am getting a problem to update the progress bar gui using clock object with multithreading in python-kivy. i am using both files .kv & .py file run the app. my main.py file: from kivy.app import App from kivy.uix.label import Label from kivy.uix.boxlayout import BoxLayout from kivy.uix.progressbar import ProgressBar from kivy.uix.button import Button from kivy.uix.popup import Popup from kivy.clock import Clock import sys, threading, os,

How to update progressbar using Clock Object with Multithreading in kivy-python?

核能气质少年 提交于 2021-02-18 17:46:47
问题 I am making an app in kivy for that i am using linux. i am getting a problem to update the progress bar gui using clock object with multithreading in python-kivy. i am using both files .kv & .py file run the app. my main.py file: from kivy.app import App from kivy.uix.label import Label from kivy.uix.boxlayout import BoxLayout from kivy.uix.progressbar import ProgressBar from kivy.uix.button import Button from kivy.uix.popup import Popup from kivy.clock import Clock import sys, threading, os,

Portable C++ Singleton - When is the destructor called

三世轮回 提交于 2021-02-18 17:45:50
问题 When a thread safe singleton has to be implemented using C++11 the only correct implementation I know is the following: // header class Singleton final { public: static Singleton& getInstance(); private: Singleton() = default; Singleton(Singleton const&) = delete; void operator=(Singleton const&) = delete; }; // implementation: Singleton& Singleton::getInstance() { static Singleton instance; return instance; } In his Book "C++ Concurrency in Action" A. Williams writes that since C++11 "the

Download multiple files concurrently from FTP using FluentFTP with a maximum value

淺唱寂寞╮ 提交于 2021-02-18 17:36:30
问题 I would like to download multiple download files recursively from a FTP Directory, to do this I'm using FluentFTP library and my code is this one: private async Task downloadRecursively(string src, string dest, FtpClient ftp) { foreach(var item in ftp.GetListing(src)) { if (item.Type == FtpFileSystemObjectType.Directory) { if (item.Size != 0) { System.IO.Directory.CreateDirectory(Path.Combine(dest, item.Name)); downloadRecursively(Path.Combine(src, item.Name), Path.Combine(dest, item.Name),

Pause a python script until an event occurs without hanging/blocking the GUI

妖精的绣舞 提交于 2021-02-18 12:48:06
问题 Trying to migrate from PyQt with Kivy and I cant even imagine a solution for this. I have thousands of lines of code that use Qt's dialogues for text input. That is, when their line of code is reached, they 'stop' the script until the "ok" button is pressed, so they can return the text input. Kivy doesnt have that functionality, so ideally, when the program needs user input, the "ok" button would call for the next function to run. Therefore I must replace all the current calls to a PyQt

Async/await vs Task.Run in C#

假装没事ソ 提交于 2021-02-18 12:16:25
问题 I am just new to this world of asynchronous stuff. Please bear with my lack of knowledge. It is said when a method encounters await ... " It tells the awaitable to run the remainder of the method when it completes, and then returns from the async method. " I did not get this part. So does it mean the method still keeps on running synchronously and waits till the awaitable returns and then proceeds with the rest of the method? If not please explain then why Task.Run is needed to run a method

Non-threadsafe file I/O in C/C++

余生颓废 提交于 2021-02-18 12:03:10
问题 While troubleshooting some performance problems in our apps, I found out that C's stdio.h functions (and, at least for our vendor, C++'s fstream classes) are threadsafe. As a result, every time I do something as simple as fgetc , the RTL has to acquire a lock, read a byte, and release the lock. This is not good for performance. What's the best way to get non-threadsafe file I/O in C and C++, so that I can manage locking myself and get better performance? MSVC provides _fputc_nolock, and GCC

Python execute playsound in separate thread

╄→尐↘猪︶ㄣ 提交于 2021-02-18 11:42:07
问题 I need to play sound in my python program so that i used playsound module for that. def playy(): playsound('beep.mp3') How can I modify this to run inside main method as a new thread. I need to run this method inside the main method if a condition is true.when it is false thread need to stop 回答1: Use threading library : from threading import Thread T = Thread(target=playy) # create thread T.start() # Launch created thread 回答2: You may not have to worry about using a thread. You can simply