I need using CSemaphore class in MFC C++ application. I have an edit1 box with multil ine and each line has a string. I'm trying to loop through edit1 box and for each string to start a thread that is using the string for specific function. I'm trying to limit the run of only one thread at the same time with semaphores but all treads start at the same time.
So when i click button1 i loop through edit1 box and start threads:
Code: void CMFCApplication1Dlg::onButton1Click() { int i, nLineCount = edit1.GetLineCount(); CString strText, strLine, mesaj; for (i = 0; i < nLineCount; i++) {
[Code] ....
While looping through edit1 box multi line and starting the threads:
Code: UINT CMFCApplication1Dlg::StartThread(LPVOID param) { WaitForSingleObject(semafor, INFINITE); // wait for semafor to signal THREADSTRUCT* ts = (THREADSTRUCT*)param; // here i'm doing some operations with the string from edit1 box ReleaseSemaphore(semafor, 1, NULL); //release the semaphore for next thread to begin }
Instead of running only one thread at a time all threads start. What am i doing wrong ?
I like to read the table and get the all PNAME into the combo box.
Using the below code i can read the table, but while loop takes 2 seconds to read 10 records in the Profilemaster table. How can i reduce the reading time?
My Code is void MainScreen::OnreadProfileName() { CDatabase database; CString SqlString; CString sDsn; CString pname;
I want to generalize my productFunction below to a template family of functions where the template merely changes the * to + or whatever else operator I wish to use.
How can I turn a template parameter into various operators? (apart from using switch statements that will reduce the performance and make the code really ugly) What kind of metatemplating method converts a compile-time constant to an operator?
This is a round robin execution. with gantt chart. arrival time and burst time. I think there is an error in my formula to get the right answer,i cant resolve it but my program is running. What is the code or the right formula??
#include<stdio.h> int main(){ int i,j=0,n,time,remain,flag=0,ts; int sum_wait=0,sum_turnaround=0,at[10],bt[10],rt[10]; int ganttP[50],ganttStartTime[50]; printf("Enter no of Processes : "); scanf("%d",&n); remain=n;
Task1 started in : 2 in milliseconds Task1 finished in : 4015 in milliseconds.
The problem is, that if i count the time with an external device, just like the timer of my watch or my cellphone s,the total time is 4,8 or 4,9 seconds, which i wouldn t expect that to happen.
The first thing i ve thought, is that it takes the ThreadPool about 800msec or 1 sec to create the thread so as to execute this task, but even if it is so, shouldn t the stopwatch count the time precisely?So , why is there a deviation between an external timer and the stopwatch ?
#include<iostream> #include<ctime> #include<boost/progress.hpp> using namespace std; class parent { public: virtual void dynamic_display(){
[Code] ....
I am getting the following as output
Calculating....Static Function is called1times The number of processor clicks is0time is0 Calculating....Dynamic function is called1times The number of processor clicks is0time is0 Static Function is called2times Dynamic function is called2times Static Function is called3times Dynamic function is called3times
I am actually trying to calculate the time to execute a statically binding method and a dynamically binded one.consider only the first four lines in my output. Why am i not getting the actual result.
I wrote program for Sequential matrix multiplication .But after execution for any input value( ex. 100,150,400) it shows the execution time is 0.000 msec.
#include <stdio.h> #include <math.h> #include <sys/time.h> void print_results(char *prompt, int N, float *a); int main(int argc, char *argv[])
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;
I have a SDI application. I created a method OnClose to handle ON_WM_CLOSE of CMainFrm. This onclose() function calls a method in cmyview.cpp. Here, I created a thread that calls global function and from this function it calls another function in cmyview.cpp. At certain condition my application should close at here, I used postmessgae(WM_CLOSE (or) WM_DESTROY). I am having an error as object reference not set on postmessage(WM_CLOSE) it is going to afxwin2.inl page where exception occurs.
Below is code snippetHere, either j or k will only be true depneds on user input)
How can I implement the paradigm demonstrated by the code below to run on WinXP?
I want to fork a process or create a thread that shares global variables with the parent process/thread.
The child process/thread monitors the progress of the parent process/thread.
I cannot find documentation for a fork function per se, a Unix term. It might be called something different for WinXP.
I would be happy to use threads instead. But I'm rusty even with Unix application threads; and I know nothing of WinXP application threads.
So any turnkey implementation that demonstrates the simplest use of process or thread functions for my purpose demonstrated below.
In either case, do "forked" processes and threads share global address space in WinXP, as they do in Unix?
I would prefer to avoid the overhead of IPC mechanisms. The "overhead" includes my own relearning curve.
The GUI screwed up my indentation. I would try to correct it. But the proper indentation appears when I edit the posting. I suppose I need to insert real tabs. Haven't figured out how (yet).
Not even real tabs work; and I cannot get the "paste as text" button to behave as I expect. What is the trick for posting indented text in this GUI?
#include "stdafx.h" #include <stdlib.h> #include <Windows.h> long curCount; int isRunning; int _tmain(int argc, char* argv[]) { curCount = 0; isRunning = 1;
I am having a strange problem trying to display a dialog from a UI thread. The dialog simply fails to display. I have a function DisplayFlashBox(), which creates the UI thread:
CUIThread* CIMUIHelper:: DisplayFlashBox(const CString &sMessage, const int nInstrumentUID) { CUIThread *pThread = new CUIThread(); pThread->SetString(sMessage); pThread->SetInstrumentUID(nInstrumentUID); pThread->CreateThread();
[Code] .....
The dialog doesn't display. When I tried debugging, I found the OnInitDialog() method of CIMFlashBox class doesn't actually return. Very strange. I tried calling the DoModal() method instead of Create, but doesn't display the dialog either.
I'm writing a program where a user keeps entering numbers until "0" is entered.Once "0" is entered the loop ends and It displays the mean. Problem is it counts the "0" in the average.
e,g:
Enter number 1: 5 Enter number 2: 2 Enter number 3: 3 Enter number 4: 0
The mean is 2.5. But I want it to only count everything before the "0". (5 + 2 + 3) / 3 = 3.333333
I have main thread that creates an WebBrowser2 COM object. and i want to invoke JScript functions on it from another thread. i try to use GIT but still doesn't work for me.. there is a problem with marshal WebBrowser2 for JScript?
Can local variable be passed as the parameter for a new created thread procedure? Here is the example code:
Code: void CDLG::some_function() { CString strFileName="abc.doc"; //local variable, can it be valid for being passed into the following new thread??? //Can strFileName still be accessed from within the stack of thread procedure? ::AfxBeginThread(ProcessContentThread,(LPVOID)&strFileName); }
[Code]...
There is another method using variable on the heap,
I test these code, both methods work as expected, but I doubt whether the first method is a good way. OR if only the second method is the correct way to pass a parameter to a thread.
I have a thread with a while(1) loop in it. When the user push the stop button I would like that thread to end.
I thought about creating a bool and checking its value periodically in the thread and when I push the stop button I change the value of the bool for that the thread breaks out of the loop and finishes.
I'm the author of a realtime MIDI software called ChordEase which makes use of the MIDI aspects of the multimedia API, specifically MIDI input callbacks. In XP and before, these callbacks originated in the kernel and therefore had realtime priority by definition, but from Vista on, they originate in thread pool threads, and have a priority of zero. This is a problem because at priority zero they can be blocked by the GUI thread, causing serious latency, and I have proved that such blocking occurs.
I have experimented with raising the callback thread priority, using either of the following methods: 1) calling SetThreadPriority within the MIDI input callback function, and then setting a flag so that it isn't done repeatedly, or 2) creating a DLL that catches thread creation via DLL_ATTACH_THREAD in DllMain, and calling SetThreadPriority there. The first method is slightly wasteful since the flag has to be tested for every MIDI input event, but it also has the advantage of only affecting the MIDI input threads, whereas the second method affects all threads in the pool regardless of what they're used for. Neither method appears to cause any harmful effects but they make me nervous*. Other possible methods would include 3) using the thread pool API to raise the priority of the pool (assuming I could gain access to the pool handle somehow), or 4) permanently lowering the priority of the GUI thread, which I'm very reluctant to do because of the risk of unintended consequences.
I'm assuming the MIDI input callbacks are using threads in the default thread pool though I haven't actually proved this. Assuming that's so, are these threads private to my application, or is my application sharing them with other applications? Is there a safer way to achieve the result of increasing the priority of MIDI input callbacks? It's incredibly frustrating that MS would change the behavior of MIDI input callbacks so drastically without even telling anyone, but that's how it goes!
[URL] ....
*See for example theses warnings about changing thread pool priorities : [URL] ....
My program has a large version of this, where every leaf class is singleton, and pointers of the base class to represent each possible path are stored in a map during compile time. I have it working as follows:
But System::initializePrototypes() is constructing the map manually, and I want to use recursion somehow, because my hierarchy is much bigger than this. It's also easy to miss a path doing it the above way, and when new classes are added to the hierarchy, it will be a nightmare to update the map. So the ideal solution is recursion constructing the map perfectly--and when new classes are introduced, nothing needs to be added to System::initializePrototypes().