C++ :: Handle Exception In Multi-threaded Environment

Oct 24, 2014

Here is the code,

Code:
void foo() {
Acquiring lock
do something...
Func();
Releasing Lock
}

If the function Func throws an exception, there is potential deadlock issue. Then I handle exception like this,

Code:
void foo() {
Acquiring lock
do something...
try{
Func();

[Code] ....

Is this a good practice? I wonder how I can apply RAII in handling exception here.

View 2 Replies


ADVERTISEMENT

C++ :: Multi Threaded Insertion Into STL Map?

Aug 25, 2014

Suppose multiple threads are are trying to insert into a STL Map, both are trying to insert with same key. As per my understanding it will not cause any issue till you invalidate the iterator. Here as per me it will not invalidate the iterator.

View 2 Replies View Related

C/C++ :: How To Handle Exception In Constructor

Apr 14, 2012

If a class A contains an array of objects of another class B.. And in the constructor of A, while constructing objects of B, any one object throws an exception, then how can we guarantee to release all the memory acquired.. so that there is no memory leak..

class B{};
class A{
public:
  B Array[100];
  ...
};  

In the above code, if in constructor of A, suppose 99 objects of B are constructed successfully, but 100th object throws exception, then how can we guarantee to release all the memory acquired by the other 99 objects?

View 1 Replies View Related

C :: Returning Value From One Threaded Function To Another

Apr 15, 2013

I am using two threads and i want to take value of a function from one thread and use it in other. I am not good at the concepts of threads. Here is the following code:

Code:
void ThreadA(void const *argument){
uint32_t status = I2S002_FAIL;

status = I2S002_Config(&I2S002_Handle0, &I2SConfig_U0C1_A);
if (status != DAVEApp_SUCCESS) {

[Code] ....

So, i want to use the return value of temp_buffer from ThreadB into Thread C and want to put this value to TXBuf in ThreadA...

View 1 Replies View Related

C :: More Packet Received Than Threaded Sender Sent

Dec 15, 2014

Questions : I am running a client Server Program whose Sender and Receiver loop is given below .I have multi threaded Sender using OMP .As per My logic Receive should receive same amount of data send by Sender ,But its receiving more packet than Sender sent .I am not able to identify the Bug !!

Code:
/*
Running As Follow :
gcc UTGen.c -o Sender
gcc UTGen.c -o Receiver

./Receiver -m 0 -p 5000 -z 256 -P t

export OMP_NUM_THREADS=4
./Sender -m 1 -s localhost -p 5000 -z 256 -T 10 -P t
*/

[Code] .....

View 3 Replies View Related

C++ :: Exit Two-threaded Program With User Input?

Sep 9, 2014

// clang++ -g -std=c++11 main.cpp -pthread
#include <iostream>
#include <thread>
#include <unistd.h>
void thread1(void) {
while(1)

[code]....

Thread 1 does some background work, and thread2 is waiting for the user's input. If I join thread1 then the app can never exit. If I neither join nor detach thread1 then I get "terminate called without an active exception Aborted" which is not a good thing to have. If I do detach on thread1 does thread1 ever terminate? If not, how to terminate it? Also, how do I check if it's terminated or not?

View 2 Replies View Related

C++ :: Debug Multithreaded Application In Unix Environment?

Mar 3, 2013

How can we debug the multithreaded application in unix environment?

View 1 Replies View Related

C++ :: Exit Two Threaded Program With User Input?

Sep 8, 2014

Code:

// clang++ -g -std=c++11 main.cpp -pthread
#include <iostream>
#include <thread>
#include <unistd.h>
void thread1(void) {
while(1) {
int i = 88 * 2;

[Code]...

Thread1 does some background work, and thread2 is waiting for the user's input.

If I join thread1 then the app can never exit. If I neither join nor detach thread1 then I get "terminate called without an active exception Aborted" which is not a good thing to have.

If I do detach on thread1 does thread1 ever terminate?
If not, how to terminate it?
Also, how do I check if it's terminated or not? -- I realize it's platform specific, I am on Linux.

View 5 Replies View Related

C++ :: Implementing Single Threaded Asynchronous TCP Server

Jan 12, 2012

I need implementing asynchronous single threaded TCP server using boost asio..

View 3 Replies View Related

C :: Program To Recognize Pattern Of Signals (linux Environment)

Mar 6, 2015

I need to write a c program that can receive signals and recognize a certain pattern (SIGUSR1, SIGUSR2, SIGUSR1, SIGUSR2). once the pattern is caught the program terminates itself.

I am able to send the signals to the program from a different process, but I am unsure on how to get the signal handler to recognize the pattern. here is what i have so far:

Code:
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
sig_atomic_t sigusr1_count = 0;
sig_atomic_t sigusr2_count = 0;

[Code] .....

I just need getting the program to be able to catch that specific pattern.

View 4 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++ :: Cooperative Multitasking System - Single Threaded Application

Jan 19, 2013

I'm trying to get around the concept of cooperative multitasking system and exactly how it works in a single threaded application.

My understanding is that this is a "form of multitasking in which multiple tasks execute by voluntarily ceding control to other tasks at programmer-defined points within each task."

So if you have a list of tasks and one task is executing, how do you determine to pass execution to another task? And when you give execution back to a previous task, how do resume from where you were previously?

I find this a bit confusing because I don't understand how this can be achieve without a multithreaded application.

View 2 Replies View Related

Visual C++ :: Floating CDialogbar On Multiple Screen Environment

Jul 11, 2014

I have an problem with a CDialogbar if my app runs on a system with two screens (side by side). I can not resize it while the CDialogbar is in floating state on the second screen.

I figured out that the problem is the mfc-function CDockContext::Stretch().

It limits the CDialogbar to the primary screen (using ::GetDesktopWindow() to verify the position).

What can I do?

View 2 Replies View Related

Visual C++ :: Dragging And Dropping Functionality In Windows 8 Environment

Jul 14, 2014

i have developed an application in which i have icons in left side pane of application which can be dragged and dropped in client screen. Application is working fine with all the resolution except 1920x1080.

when setting the resolution to 1920x1080 while dragging icons to client area, icon is not attach to mouse pointer. instead there is a gap between the mouse pointer and the icon. i wrote code to identify the screen resolution but it does not seem to recognize 1920x1080 resolution. below code is giving incorrect resolution for 1920x1080 setting.

RECT actualDesktop;
GetClientRect(GetDesktopWindow(),&actualDesktop);

value of 'actualDesktop' variable is {top=0 bottom=783 left=0 right=1536} which is incorrect. according to current resolution size value should be {top=0 bottom=1080 left=0 right=1920}. Due to this, all the icons while dragging are adjusting according to incorrect resolution setting.

how to identify the issue and if there is any limitation with respect to screen resolution in VC++ 6.0 with windows 8 environment.

I am getting same issue when compiling in VS2012 in windows 8. Code does not seem to recognize 1920x1080 resolution setting and downgrading my application look and feel by setting it to lower resolution.

View 1 Replies View Related

Visual C++ :: Static Class Member In Multithreaded Environment

Nov 21, 2014

I have a class having static member.I have get and set methods which will Get and Set Values to this variable. In a multithreaded application does it have any thread safety issues.

Class a {
static int b;
void Set (int c);
int Get();
};

View 10 Replies View Related

C++ :: Calculate Something More Than A Var Can Handle?

Jan 1, 2013

Let's say I want to calculate something like PI using some algorithm, but with the number of digits I want to.

View 1 Replies View Related

C# :: How To Close Overlapped I/O Handle

Nov 6, 2012

Consider the following code which closes an overlapped I/O serial handle during application shutdown.

Code:

Win32Com.CancelIo(hPort);
Win32Com.CloseHandle(hPort);

It works fine under .NET 2.0 but after switching to .NET 4.0 it crashes on the CloseHandle. Removing CancelIO doesn't work.

What the correct way is to close an overlapped I/O handle? And why is there the difference between NET2.0 and 4.0?

View 5 Replies View Related

C :: Handle Cmd Line Arguments?

Jul 30, 2013

How to handle cmd line argument in c.

View 5 Replies View Related

C++ ::  how To Handle Async Operations

May 29, 2013

I've been thinking over this for long time... For example, when a button is clicked, print a string "clicked" after 5 seconds. (the button won't be blocked)

Thread should be the only way to do this:

btn.on_click = []() {
thread thrd([]() { sleep_5_seconds(); cout << "clicked" << endl; });
thrd.start();
};

the local variable thrd is destructed right after it starts, which may cause a crash, so use new operator:

btn.on_click = []() {
thread* thrd = new thread([]() { sleep_5_seconds << "clicked" << endl; });
thrd->start();
};

The thrd never get deleted

How would you solve problem like this?

View 2 Replies View Related

C++ :: SDL Handle Mouse Motions And Clicks?

Sep 14, 2013

I have a game that I'm trying to create but I don't really know how to handle mouse motions yet. I have read the LazyFoo.net lesson 9. And I have too searched around on Google but haven't find any good article for what I want to do

But what I want is to check if the mouse is OVER the START button of the game and if the user has pressed the LEFT mouse button the game should START.

This works when I am hovering over the area there I want the mouse to do something:

Code:
else if (event.type == SDL_MOUSEMOTION)
{
if (event.motion.x == 0)
{
quit = true;
}
}

I do not know how to check this. The START and QUIT button is in the middle of the screen and I don't know how to position the mouse there either.

View 5 Replies View Related

C++ :: SDL - How To Handle Mouse Motion Input

Oct 19, 2013

I am using SDL 2.0. But I don't know how to handle mouse input. Do you think you can explain of how to do that? Or give me a link that explains that really great?

I know how to handle a mouse button that presses down for a sec.

Code:
if (event.type == SDL_MOUSEBUTTONDOWN){
if (event.button.button == SDL_BUTTON_LEFT){
// Do something . . .
}
}

But not how to handle the mouse input of what the mouse is hovering over and that.

Like in a start menu of a game. I want a button for example to appear blue when I hover over it and when I click on it. It should start the game for example.

View 6 Replies View Related

C :: How To Handle Sound And Music Files

Mar 11, 2013

I do not know any of the functions to do this, and when I looked on the internet all the functions I saw were mainly non-standard.

View 12 Replies View Related

C# :: How To Properly Handle Thread Failures

Feb 9, 2015

I have an application that uses an array of threads to call a method along with thread.join(). I was just wondering what would be the best way to handle the thread in case if one of the thread fails? Should I put a try catch block on the method that is being called or should I put the try catch block on the array of threads, or is there any other proper way to handle failed threads?

View 3 Replies View Related

C/C++ :: How To Handle Floating Point Error

Nov 7, 2013

And it is not running successfully... abnormal termination

View 3 Replies View Related

Visual C++ :: Passing File Handle To DLL?

May 6, 2013

I write a small application and using the following API to open the file:

hHandle = CreateFile(lpszFileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

Then I pass the hHandle to a DLL exported function, in that function, I will call

DWORD dwFlags = 0;

ASSERT(GetHandleInformation(hFile,&dwFlags) != 0)

to check if the handle is valid. However, the assert fails. And I use GetLastError to get the error code 6, which means invalid handle.

What is the problem with my codes?

View 4 Replies View Related

Visual C++ :: Pass A Handle To A Function

May 5, 2013

Visual C++ 2010

I'm using SFML with Visual C++ and need to pass a handle to a function. I've tried to find this on the web with no luck.

The handle happens to be a sprite defined as: sf::Sprite Numbers(MyNumbers);

Now I want to pass "Numbers" to a function.

-
-
getFrame(Numbers);
-
-
???? getFrame(??????) {
Numbers.SetSubRect(sf::IntRect(0,0,63,63));
return ????
}

How do I do this?

View 1 Replies View Related







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