C++ :: How To Prevent The Main Thread From Blocking

Feb 14, 2014

I have an issue where I iterate through devices and make driver API calls. Unfortunately, these calls take too much time and they are interrupting my real-time scheduler. I have 12 cores, of which one is 100% and the others are < 1%.

I'd like to multi-thread this thing. So far, I've replaced:

for (DeviceIterator d = devices.begin(); d != devices.end(); ++d) {
d->Write(words, numwords);
}

with

void* ThreadedWrite(void* p) {
WritePackage* wp = (WritePackage*)p;
wp->device->Write(wp->words, wp->numwords);
delete[] wp->words;
delete wp;

[Code]...

My problem is that this didn't improve performance at all. The main thread still takes too long to execute. Is there something I need to do to prevent the main thread from blocking?

View 2 Replies


ADVERTISEMENT

C# :: One Thread Trying To Pass Data To Another Thread Using Serial Port

Jul 30, 2014

I have a class which I wrote and one of its object is "SerialPort" .NET class. In my MainWindow I created instance of my class called "SerialPortComm", then I send through some functions of mine, commands to the Serial Port, and I receive answers through "DataReceived" event.

But when I trying to use Dispatcher.BeginInvoke to write my data I have received (successfully), nothing shows on the RichTextBox which I'm trying to write to.

What can caused that, and How I can make it works?

SerialPortComm.cs

public partial class SerialPortComm : UserControl {
public SerialPort mySerialPort = new SerialPort();
public void Open_Port(string comNumber, int baudRate) {
mySerialPort.PortName = comNumber;
mySerialPort.BaudRate = baudRate;

[Code] ....

View 7 Replies View Related

C# :: MultiThread Blocking Updates During Read

Oct 6, 2014

I have a class holding my data strcuture:

// Holding real time option data - should be thread safe
public class OptionRTHolder {
ConcurrentDictionary<double, Quates> book_calls;
ConcurrentDictionary<double, Quates> book_puts;
ConcurrentDictionary<double, List<Single_qoute>> transaction_calls;
ConcurrentDictionary<double, List<Single_qoute>> transaction_puts;
ConcurrentDictionary<double, int> volume_calls;
ConcurrentDictionary<double, int> volume_puts;
DateTime curr_time;
}

I get a stream of data messages, that come in order, each message carries a time and data. I have many threads in paralell pulling messages and in turn update the data strucutre as follows:

Quates and volume data are just overrun (new value overrun former values), also thier size and meta data is fixed (they don't grow post init).

Via the list I have a problem, I would want to lock only the list I am working on. so other lists can update in paralell, what I had in mind was to warp the list in order to warp the add/get calls to make it thread safety, this I think will achieve this goal and I would like to get some assertion from this forum if you may.

Here come my real problem, there are points in time I want to read/copy this structure, during this time I want to block all updating threads as I want to freeze structure in time, is that achiveable ? Idea that I had is to use something like aquire that will get a function (update/read) and a flag that will cause a lock when the read is on...something like that.

View 3 Replies View Related

C# :: Blocking File Action Access?

Apr 20, 2014

My problem: I want to make an application that is going to block the action of some files (It is anticheat files actually).

how do I make code to block the application's action?

Maybe there is another way to do that? I need to use Cheat Engine in game, and anticheat blocks it, so I thought if I'll block the activity of the anticheat it couldn't detect the Cheat Engine...

View 2 Replies View Related

C :: Implementing Non Blocking UDP Socket By Select Function

Apr 22, 2013

I wanted to create an asynchronous/non-blocking udp client server application where the client and server were supposed to chat away with each other without waiting for each other's turns. I came to know that this could be done by select()... here is my Server(Mentioning only the communication part):

Code:
fd_set readfds,writefds;
while(1){
FD_ZERO(&readfds);
FD_ZERO(&writefds);
FD_SET(sd,&readfds);
FD_SET(sd,&writefds);

int rv = select(n, &readfds, NULL, NULL, NULL);

[Code] .....

At first on the server side I wrote:
int rv = select(n, &readfds, &writefds, NULL, NULL);

But that led to the printing of an entire empty array on the server console when the server initialised in addition to the fact that communication between the server and client was not proper. removing "&writefds" did remove the redundant data but the improper communication issue still persists...

View 3 Replies View Related

C++ :: How To Make Blocking Fetch Call On Queue

Mar 5, 2015

I have a thread that fetch elements from a std:queue, which are pushed from other threads. My question is how can I fetch elements from the queue in a blocking mode, what I mean is if there are no elements in the queue then the fetch call will block until at least one element is pushed. Of course I want to do it this way to avoid polling.

View 6 Replies View Related

Visual C++ :: Blocking Keyboard Play / Pause Button In Windows 8?

Mar 27, 2014

I am writing an application that needs to temporarily disable the Play/Pause button that appears on multimedia keyboards.

Normally, a key can be blocked quite easily by installing a low level keyboard hook (WH_KEYBOARD_LL) where the KeyboardProc intercepts the key (in this case VK_MEDIA_PLAY_PAUSE) and returns a "1" instead of calling CallNextHookEx. I have tried this with other keys (including the Windows key VK_LWIN) and this works perfectly. I also have no problems with this method under Windows 7 where all keys, including VK_MEDIA_PLAY_PAUSE get blocked.

Windows 8 is a different story. When my application has input focus, everything works as expected, meaning the VK_MEDIA_PLAY_PAUSE key gets blocked and no other application responds to it. However, when my application loses focus, my hook procedure gets called (this was verified by sending out a OutputDebugString) but other applications respond to key even though I return a "1". As soon as my app gets focus again, everything is block as it should.

After some investigation, I found that the multimedia keys not only generate keystrokes but also generate WM_APPCOMMAND messages so I added ShellProc (WH_SHELL) hook with the following hook procedure:

LRESULT __declspec(dllexport)__stdcall CALLBACK ShellProc(int nCode,WPARAM wParam,LPARAM lParam) {
// Do we have to handle this message?
if (nCode == HSHELL_APPCOMMAND) {
OutputDebugStringX(">>>>> HSHELL_APPCOMMAND");

[code]....

This procedure is only getting called when my app has input focus. Whenever I have input focus and return "1" the Play/Pause command gets blocked. As soon as I lose focus the procedure does not get called/hooked.

As I have mentioned, the code works for other keys, just not the multimedia keys.

Alternatively, another way of blocking the multimedia keyboards Play/Pause button?

View 6 Replies View Related

C++ :: How To Prevent Loop Running Over

Feb 18, 2014

i am writing a function that takes a delimited string and splits the strings into it's respective words according to the delimeter.

1) iterate through string and store delimeter position in vector array.

2) iterate through again and use substr to split into words and store again in a vector.

I then have a dictionary file, and am comapring each values in the string with each in the dictionary, problem is that it overruns the loop and obviously gives a subscript out of range error.

Code:
#include <iostream>#include <fstream>
#include <vector>
using namespace std;
//Start with string inputString
//Find delimeters ::pos as ints and stores positions in vector <int> array
//Run though string using 'find' and seperate string by positions of char32s
//Build vector<string> array of individual words in string
//Open dictionary file and loop though testing each words in vector string array against each word in dictionary

[code]....

View 4 Replies View Related

C :: Prevent Duplication When Insert Age

Oct 17, 2014

I created program that insert employes data and then print their data but never accept duplicate age if user entered duplicated age prompt him to enter another age (age must be unique)

Code:
#include<conio.h>
#include<stdio.h>
#define size 3

struct emp
{
int age,overtime,dedcution,netsal;
float salary;

[Code] .....

View 3 Replies View Related

C :: Prevent To Type Zero As The First Digit In Value

Apr 4, 2013

I want to prevent to type zero as the first digit in value in c code

Code:
char next_buffer[ 5 ];
int frame_counter;
int digit_counter;
memset( cmd->next_buffer, 0, sizeof( cmd->next_buffer ) );
cmd->frame_counter = 0;
cmd->digit_counter = 0; Code: if( arg && isdigit( arg[ 0 ] ) {

[Code].....

this write in text box numbers from keypad for example

5 0 2 4 9

After each typed digit, here is a underscore line waiting for the next to type next digit. I want to prevent users to type zero as the first digit in value.

View 4 Replies View Related

C++ :: Null Statement - Prevent Optimization

Dec 7, 2014

Recently I was looking into embedded programing of AVR microcontrollers.

At this site [URL] ....

I have encounter some code that implements delay

asm volatile ("nop");

From what I understand it is assembler code that creates delay - one processor clock long.

For C/C++ language it should be like ; or {} = null statement.

Now my question is how to implement this C/C++ code and prevent my compiler (WinAVR: AVR-GCC) to delete this command during optimization (-Os or -O2). Or is it simply better to use the assembler function.

I know I can use for-loop

volatile uint8_t foo
for(foo=0; foo<2; ++foo){}

but for that I have to create a variable = wasting 1 byte of RAM; correct?

View 11 Replies View Related

C/C++ :: Prevent Endless Output Of Sentences?

Nov 16, 2014

After I have compiled and executed code below, and I have made an input of a string, the while loop takes over the control and outputs an endless flow sentences. How can I make sure when an input of string is made, such a thing does not happen? In Python, one can make a type check by the use of type() command, but such a command does not exist in C, so how can I prevent an endless output in case a string input is made by the user?

(The code below is supposed to check whether the number entered by the user is divisible by 7 or not.)

#include <stdio.h>
int main() {
int a = 0;
printf("Input a number!");
while (1 < 2){
scanf("%d", &a);
if (a % 7 == 0) {

[Code] ....

View 3 Replies View Related

C# :: Prevent Sending Multiple Emails

Dec 10, 2014

I have some code which triggers an alarm when an ascii number is read in on the com port:

In that code, i have it send an email to let me know i have an alarm. The problem is it keeps sending the email over and over until i cancel the alarm. Inbox gets full real quick!

Im having trouble implementing a way to send the email just once! Ive googled as much as i can find but i cant get any way to work.

//QT TANK TEMP TOO LOW:
if (ALARM_TYPE_Value == "5") {
ALARM_TYPE_tb.BackColor = Color.Red;
ALARM_TYPE_tb.Text = " **ALARM**" + Environment.NewLine + " ";
ALARM_TYPE_tb.Text += "

[Code] ....

View 4 Replies View Related

C/C++ :: Prevent Duplicate Entry When Insert Age

Oct 17, 2014

I created program that insert employes data and then print their data but never accept duplicate age if user entered duplicated age prompt him to enter another age (age must be unique)

Here is my code

#include<conio.h>
#include<stdio.h>
#define size 3
struct emp {
int age,overtime,dedcution,netsal;

[Code] .....

View 1 Replies View Related

Visual C++ :: Prevent Executable From Running?

Aug 30, 2013

I would like to programmatically monitor a directory for new files, and if the file happens to be an executable, I want to prevent it from running. Something like a AV program.

However, I don't know where to start. Simple is best.

View 9 Replies View Related

Visual C++ :: Prevent DLL From Being Loaded / Injected

Dec 12, 2012

If you're writing a .dll you can prevent that dll from getting loaded into some processes by returning false from the dllmain.

I'm looking for a way to do it the other ay around. I have an exe, and I want to prevent a certain hook dll from getting loaded/injected into my exe.

A customer is running some software which loads a hook dll into our exe, and this is subsequently preventing our application from running as intended. Both our software as well as the third party app is required, and there is no way to get the third party dll changed. (no longer supported).

View 2 Replies View Related

C++ :: Prevent The Loop From Reading The Last File Line Twice?

Oct 19, 2013

I know how to do it in C, but in C++?

Here is my code. Let the variables be of type double.

Code:
while(infile) // Will read the last line twice
{
if(!N)//Read first line of file
{
infile >> d;
infile >> N;
infile >> epsilon;
infile >> t;

[Code] .....

View 8 Replies View Related

C++ :: How To Prevent Someone Passing Classes To Function Template

Sep 13, 2013

Let say i have a following scenario:

a function like this.

Code:
template <typename T1>
print (T1 x){
cout << x << "
";
}

How do I prevent user passing a class or a structure or aanoter function to my function print. I mean i know if a wrong thing is passed that i'll get an error eventually but is there a way to explicitly check what has been passed. How is this done usually ?

View 6 Replies View Related

C :: How To Prevent Fgets From Reading The New Line Character

Mar 12, 2013

i am trying to read a string using fgets and storing in an array i want to prevent fgets from storing the new line character on the array using the shortest means possible..

View 2 Replies View Related

Visual C++ :: How To Prevent A Window From Being Moved Or Resized

May 20, 2014

I know I can set the window properties on creation, but I'm trying to figure out how to prevent a window from being able to be moved or resized. I've been looking online and it looks like it involves overriding the WM_SIZE, WM_SIZING, or perhaps the WM_WINDOWPOSCHANGED message handlers. I want to be able to have a menu option that "locks" the window position, and of course allows normal window behavior when the option isn't checked.

View 1 Replies View Related

C :: Language Program Environment Does Nothing To Prevent Buffer Overflows

Sep 25, 2013

TheC language program environment does nothing to prevent buffer overflows ..... is there any pros to the obvious cons of this?

View 3 Replies View Related

C :: How To Prevent A User From Closing Output Screen During Execution

Sep 17, 2013

I created a C program that extracts some information from computer and displays it on screen. It is completed today and is going to be applied to startup programs of domain machines. It runs at logon and takes somewhat 5-10 seconds to finish execution. The output is shown on console screen & user can either close the window by clicking on 'x' or pressing 'Ctrl+c' during execution. How do i prevent both of these events?

Basically the most time consuming processes are

Code: popen("systeminfo","r");
popen("wmic qfe get installedon","r");

1st command is getting OS name,version and hotfixes installed.
2nd command gives me the date of updates installed.

I then filter out data & print required information only.

View 3 Replies View Related

C++ :: Prevent Destructor Delete Member Pointer From Constructor

Dec 3, 2013

I have little problem which causing memory leaks.

Parent > Multiple Child(Parent parent) > Child destructor deleting parent => next Child destructor crash

Example code: without using:

class Parent {
public:
Parent() {
for(int i = 0; i < x; ++i) {
for(int j = 0; j < y; ++j)
childs[i][j] = new Child(this);

[Code] ....

If you read code, on Parent destructor i = 0 & j = 1 its going crash.

Parent will be deleted aswell, but it give me assert: _block_type_is_valid(phead- nblockuse)

View 3 Replies View Related

C++ :: Input Validation - Prevent User From Entering Characters Or Symbols Instead Of Numbers?

Jul 19, 2013

How do I prevent user from entering characters or symbols instead of numbers?
int num;
cout<<"Enter a number."<<endl;
cin>>num;

Also, how do I prevent user from entering a number instead of a character?
char c;
cout<<"Enter a character."<<endl;
cin>>c;

View 9 Replies View Related

C++ :: Access Objects From Another Thread

Jun 25, 2013

I have the following code below. I am getting a memory access violation when accessing cmd->query_string in the loop function. The loop() function is running in another thread. The cmd object appears to be destroyed after calling the send_command function. How do I create an object on the heap and access the query_string.

std::list<my_command_message_que*> my_command_que;
void loop(){
if(my_command_que.size() > 0){
my_command_message_que * cmd = my_command_que.front();
std::cout << cmd->query_string;

[Code] ....

View 2 Replies View Related

C++ :: Passing Parameters To A Thread

May 9, 2013

I've been using threading for a while, that was no needing parameters. so I used for example the following line :

_beginthread(functionName, 0, (void*)10);

and it worked great...

but now I have a function that has an int parameter (int num), and I dont know how to transfer it using _beginthread...

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved