C/C++ :: How To Use Map In Multithreading

Jan 11, 2013

I have one input file having almost trillions of records.

Input:
Key Value
a XYZ
b xyz
. ...
. ...

How to store the above data in multithreaded map and retrieve in the same manner?

View 2 Replies


ADVERTISEMENT

C++ :: Multithreading - Demonstrate Use Of Semaphores

Feb 27, 2014

I have come across below code to demenostrate the use of semaphores

#include <pthread.h>
#include <semaphore.h>
#include <stdio.h>
#include <stdlib.h>
#define NITER 1000000
int count = 0;
void * ThreadAdd(void * a)

[Code] ....

Why the question of syncronising threads and mutexes and semaphores come into the picture when we join threads?

Like in the above example we have joined the first thread and then second thread so that main process will pause for the first thread to finish as its joined and then main process resumes and gives control to second thread and pauses till its finished as this thread is also joined.

Then where is question of simultaneous access?

First thread does its job and ends itself.
Second thread does its job and ends itself.

I wonder why there is need to use semaphores or mutexes in this example? I am very new to Multithreading and this question bothers me as to why we have to worry about simeltaneous access when we can join threads and can make control wait till that thread ends?

View 10 Replies View Related

C++ :: Multithreading - How To Modify Shared Object

Aug 24, 2014

class MyOwner {
...
int m_count;
bool b_locked;
};

[Code] ....

I am using an API where I create many MyObjects on the heap, and the API uses a separate thread to send messages to each object. Each MyObject contains a pointer to MyOwner.

Suppose I want to keep a count of all messages received in all MyObjects: How can I do this in a thread safe way?

I am assuming that the code I have written above will not be safe--at the very least it seems that it would potentially miss message counts when it was locked--not the worse case scenario for me. I am most concerned about not causing the application to crash.

View 5 Replies View Related

C++ :: Program Crashing On Exit While Multithreading

May 11, 2014

I was writing a program and it started crashing on exit (segment fault), after the 'return 0' in main(). I figure it's an std destructor.

I started with the program I was writing and just stripped out as much as I could, while making sure the crash persisted. If I remove any of the remaining code the crash disappears, even the seemly unrelated or scoped code.

#include <iostream>
#include <fstream>
#include <condition_variable>
#include <mutex>
#include <thread>

/* Call stack results:

[Code] ....

View 2 Replies View Related

C/C++ :: Simultaneous Reading And Write From And To Text File Using Multithreading

Feb 13, 2013

Simultaneous Reading and write from and to a text file using Multithreading in c/C++

View 1 Replies View Related

C++ :: Creating Databases And Indexing One Image Per Database - Multithreading Synchronization

Nov 1, 2013

My below code is createing databases(database here is a kd tree) and indexing one image per database. I have two classes LastDatabaseTndexingPolicy and another forwardingDatabaseaccessor.cpp .

I am calling the GetDatabaseToAccess() function from forwardingDatabaseAccessor.cpp class .GetDatabaseToAccess() function is present in LastDatabaseTndexingPolicy class and it returns the database created as a pointer and using that database pointer we call another function which actually indexes the image to the database .

Now my issue is i am not able to have multiple threads act on the following functions as DatabaseAccessor_ptr db which is in the following file is coupled with two functions and however i put locks in the LastDatabaseTndexingPolicy file as below i end up getting synchronization issue ..........

Hence now i am using a single lock in forwardingDatabaseAccessor.cpp and serializing the code,. How can i change my design to parallelize this code .........

In ForwardingDatabaseAccessor.cpp we are calling function from LastDatabaseTndexingPolicy as shown below:-

DatabaseAccessor_ptr db is something which needs to be synchroinized. I tried createing 256 databases with one image each and when i run this code i ended up creating 175 databses and though i was restricting in code with locks that every database has only one image i ended up having two images in single database ..... ideally i had to get only one image per database but i got two images in few of them hence instead of 256 database this code created 175 or so databases.

indexing::IndexReturnValue ForwardDatabaseAccessor::index(cv::Mat image,
const std::string& imageName, features::Camera::Type indexCameraType,
features::Camera::Type recogCameraType) {
DatabaseAccessor_ptr db = this->IndexingPolicy_ptr->GetDBToIndex();

[Code] .....

View 1 Replies View Related







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