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


ADVERTISEMENT

C++ :: Passing Classes As Parameters?

Oct 14, 2013

how would I pass this parameter and how/why is it not working this way? I've tried many different methods to this and I can't quite seem to figure it out.

studentList student;
student.push(252875, "Jerry", "UTPA");

What I thought would work

class student {
public:
int id; //student ID number
string name; //student’s name
string university; //student’ university
};
//student list is a doubly linked list of students.

[code]....

My header file.

I am honestly not sure where to start here. I would assume that it would know what to do with the varibles but it doesn't seem to want to accept them. It gives me

Error1error C2660: 'studentList::push' : function does not take 3 arguments

2IntelliSense: no suitable constructor exists to convert from "int" to "student"

View 11 Replies View Related

C/C++ :: Functions Passing Size Of Arrays As Value Parameters?

Mar 11, 2014

we were given this code:

// Music Shuffle Program
// This program takes an array of strings and randomly permutes their order.
// This allows us to generate new song shuffles.
#include <iostream>

[Code]....

or are they referring to something else?

View 4 Replies View Related

C++ :: Setting Up Counters - Using Function / Passing Parameters

Jun 30, 2012

Need setting up counters for this program which should

Given a file of text, assume that
a "word" is 1 or more consecutive, non-whitespace characters
a "sentence" is a series of words terminated by either a period, exclamation point, or question mark

Design a C++ program (using functions/passing parameters) that will

-interactively prompt for and read the name of an input file
-interactively prompt for and read a string to search for
-open the input file (using an input filestream variable) and with one pass through the file
-count the number of "words" in the file
-for each word, make sure all letters, except the first, are lower case - leave the first character unchanged
-count the number of "sentences" in the file
-count the number of letters in the file (A-Z,a-z)
-count the number of consonants in the file (consonants are letters that are not vowels - the vowels are: a, e, i, o, u, A, E, I, O, and U)
-count the number of nonwhitespace characters in the file that are NOT letters
-count the number of times the search string is found in the file (must be an exact match) - search for matches AFTER upper case letters have been coverted to lower case

View 2 Replies View Related

Visual C++ :: Passing As Parameters To A Function Characters Coded In UTF 8

Apr 9, 2014

I'm using the Visual C++ Express 2008 and i need to pass as parameters to a function characters coded in UTF 8. My environment is Windows 7. The editor of the VC++ write in UTF 8 or UTF 16? If it writes in UTF 16 how can i change it?

View 2 Replies View Related

C :: How Arguments Handled If Passing Parameters Are Different Types Compared To Declaration

Jun 12, 2014

Suppose if i write a test program like

Code:
void function1(unsigned int var1);
int main(void) {
function1(-3);
}
void function1(unsigned int var1) {
printf("%d", var1);
}

The output is -3. how it happens the argument is unsigned but iam passing signed but still prints the signed value. My bigger question is how the arguments are handled if the passing parameters are different types compared to declaration.

View 2 Replies View Related

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++ :: 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++ :: Thread Chaining And Latency

Mar 3, 2013

I was working on a problem that was best solved with chaining threads together using a blocking thread-safe queue. Eg threads A and B pass data to each other using a queue ... a simple producer consumer design A -> B. This has two benefits: 1) being that there is a buffer between the two threads to cache for a slow consumer and 2) allows for better throughput when loads of data are high because the two can run in parallel. Most of the time the design works well under load. but I found when pushing data through the threads intermittently, i.e. once about 0.5 seconds it ran poorly, mostly from what seemed to be latency introduced during the OS waking up of the consumer thread B.

What i have come up with to solve this issue is what i call an .... Its a wrapper around a basic thread safe queue and adds one extra function called .... The idea here is that if you have a simple case (or perhaps a slightly more complicated case) of two threads in a prod cons design and you know the producer will create or received the data, process it, and then push onto the queue, why not give the consumer thread a heads up to let it know the data is about to arrive. In this case call .... In this way you can have the consumer thread in a polling state anticipating the arrival of data and avoid the time to schedule it back to a running state.

Anyway, i have some code below and I was looking to get some feedback. I have tested it somewhat and it does improve the responsiveness quite substantially.

View 7 Replies View Related

C/C++ :: Thread Appears To Run After SetEvent

Apr 28, 2014

I don't know if I've setup the thread correctly or not, but its behavoir isn't what I'd expect. I'm creating the thread within a BN_CLICKED message

typedef struct my_TNFO {
    HANDLE h_event;
    HANDLE h_thread;
    DWORD  thread_id;
    BOOL   running;
    BOOL   init;
    BOOL   canceled;

[Code] ....

progd->count was devised to stop the thread when the recursion ended by posting a message to the main window. When it reaches 1, the def procedure sends the WMU_DISC_DONE message to set the event

All that *appears* to work; however, if I cancel the recursion thread, the list view continues to populate for a bit and then deletels all but 1 item though I send the message LVM_DELETEALLITEMS.

If I move the (tmp->canceled == TRUE) test inside of the do-while, the app gets loopy.

View 4 Replies View Related

Visual C++ :: Add To Listbox Thread

Feb 15, 2015

Startthread get called to launch to update list box.

a)is it the only way to pass string to the PostMessage?. my concern is that allocate using new in each iteration each time slows it down a bit.

b)does OnAddToListBox look memory leak free?.

c)What is the best way handle m_pThread at the end?. Any way to improve it?.

Code:
UINT CMyDlg::Dump(LPVOID lparam) {
HWND *pHndl = static_cast<HWND *>(lparam);
char buffer[200];
for (int i = 0; i < 100; i++) {
sprintf_s(buf,"user %d, data %s",i, "Connected");

[Code] ....

View 8 Replies View Related

Visual C++ :: How To Check Thread With MFC

Feb 12, 2013

I use MFC Find console window and send key to console like this.

Code:
HWND w;
w = FindWindow(NULL, L"c:userspkrudocumentsvisual studio 2010ProjectsCleanVirusDebugCleanVirus.exe");

[Code]....

After program process success in console it not close console windows but it show like this in Output

The thread 'Win32 Thread' (0x1300) has exited with code 0 (0x0).

I think if I can check when VC will show this line, then I can use FreeConsole(); for close console windows.

View 3 Replies View Related

C++ :: How To Decide Which Type Of Thread To Use

Jun 7, 2014

There are gnu thread, c thread, posix thread and win32 thread which all can be used on windows platform.

How, why and when do I need them?

Code:
#ifndef C_THREAD_H_
#define C_THREAD_H_
extern "C"
{
#include <cthread.h>

[code]....

This simply won't compile with Visual C++ because there isn't any cthread.h header file there.

View 5 Replies View Related

C++ :: Creating A Thread To Display Time

May 5, 2014

I want to add a timer(clock) to my application so that it displays the system time and refreshes every second.

I have this code but it only fires once.

// this is at the top of the application

Code:
HANDLE m_threadClockTime= NULL; Code: int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPTSTR lpCmdLine,
_In_ int nCmdShow)

[Code] ....

But this code only fires once? How can I get this to fire every second (without locking up the entire application in between)....

View 5 Replies View Related

C++ :: How To Call A Thread By A Function Pointer

Nov 24, 2014

How to call a thread by a function pointer?

I get "error C2059: syntax error : '(' " on the indicated line.

Code:
#include <windows.h>#include <iostream>
using namespace std;
DWORD WINAPI Thread() {
cout << "ok" << endl;
return 0;

[Code] ....

View 9 Replies View Related

C :: Program That Uses A Single Thread And Is SLOW

Aug 27, 2013

I am writing a program, the trouble is is that it uses a single thread and is SLOW.

View 10 Replies View Related

C# :: Wait For Thread To Finish Without Using Sleep?

Apr 30, 2012

After i've created a thread,

Code:
Thread thread = new Thread(new ThreadStart(alpha.ThreadProc)); h

How to wait for that thread to finish without using Sleep?

View 8 Replies View Related

C++ :: Changing Global Variable In A Thread

Jul 28, 2013

I have a small problem with my program. It is kinda a mess but I will try to explain you what I am trying to do. I have some threads. One of it, it attempts to detect a game client. So my code is sort of like that:

DWORD ProcessID; // The process ID of the game client
void test() {
char* text;

[Code]....

So basically, its like the variable changes, but only inside the thread... why does that happen?

View 15 Replies View Related

C++ :: Thread Library - No Such File Or Directory

Jul 25, 2014

When I write a code in c++ includes thread library it says "thread:no such file or directory". How can ı use thread library .

I think I should download boost or c++11 but I couldn't do it .

View 4 Replies View Related

C++ :: Using One (dedicated) Vector Per Thread (OpenMP)

Apr 11, 2013

I recently picked up multithreading with OpenMP, so it is still new to me. While processing data, I would like to store it in a vector, as shown here:

vector<int> vect;
#pragma omp parallel for
for(int c=0; c<500; ++c) {
vect.push_back(c)
}

However, since it is multithreaded, I would like (and need!) to have one dedicated vector per thread. I haven't been able to find an example of how to do this online. Is it even possible?

View 1 Replies View Related

C++ :: Vector Get Passed To A Thread By Value Instead Of By Reference

Aug 25, 2013

I have a function :

void UpdateNotefications(vector <string> &Notefic)

Where I change a vector...

I called it with a thread :

thread t1 (UpdateNotefications, Notefic);
t1.detach();

Though I see that inside the func, Notefic has a val, and outside, it is still empty (after the function is over)...

View 6 Replies View Related

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 View Related

C++ :: Create A Thread To A Class Function

Jan 25, 2014

I'm trying to create a thread to a class function, but it doesnt work for me...

The function : void Server::RecMsg(SOCKET &socket)

the call : std::thread GetMessages(&Server::RecMsg, ClientSocket);

I get the error : "Error1error C2064: term does not evaluate to a function taking 1 arguments"

View 1 Replies View Related

C++ :: Merge Sort Between 2 File With Thread

May 29, 2014

// mergefile2norecreation.cpp : definisce il punto di ingresso dell'applicazione console.
//
// Filemerge.cpp : definisce il punto di ingresso dell'applicazione console.
//

#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[]) {

TCHAR inputfile1[MAX_PATH];
TCHAR inputfile2[MAX_PATH];
TCHAR outputfile[MAX_PATH];

[Code] .....

There is a smart way to make a merge sort between 2 file already ordered? I had try it ,and above there is my result,it works but i think that it's possible to do it in a smart way...

View 4 Replies View Related

C++ :: Thread Can't Ignore Void Datatype?

Mar 31, 2013

the compiler doesnt accept void functions used with threads (for the first time and all of sudden!?)

#include <cstdlib>
#include <thread>
#include <windows.h>

[Code]....

this is a sigment of my code. Compiler says that the error occurs in line 47 (marked by ***). Leaving out the braces makes it even worse.

View 3 Replies View Related

C++ :: VC Thread Arguments Number Limited?

Mar 2, 2013

I am using thread on VC 2012 (very close to VC 2010). When the argument list is short, it works fine. However, when I add a function with more arguments, the compiler indicates "no thread constructor match the argument list....etc", and when I reduce the number of arguments, it works.

Is there a limit about thread constructor? I didn't see this in ISO C++11 standard. How can I fix this limit?

View 5 Replies View Related







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