|
Here is the situation.
extern int var1=0;
thread1
{
var1=10;
}
thread2
{
read var1;
}
The above thing is just a scenario. My program is really long to post it here. I need to access the var1 in thread2.
Any suggestions?
Thanks
Niks
modified on Tuesday, June 16, 2009 1:17 PM
|
|
|
|
|
It is hard to answer with the provided information. Is this variable declared inside a class and the methods threads are using is in the same class? If yes, you will have access to the variable. Make sure you use proper synchronization mechanisms if you are writing to a shared variable.
|
|
|
|
|
No, it not defined inside a class. And the method threads are using different classes. My program is a audio and screen recording program. I need to record both of them for the same time and such should pass common parameter 'time' to both the threads which call different classes.
I hope this is clear.
|
|
|
|
|
Variables do not reside in a thread - they reside in memory.
The memory for your process is shared by all threads of that process.
Therefore, you access variables the same way you always do.
As mentioned before, if more than one thread can access a variable
at the same time, you may need to synchronize access to the variable.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
sounds like a weird problem as others have pointed out access should be available to all threads within the scope of a process.
but if for some reason it doesnt work like that maybe you could use PostThreadMessage()???
something like
void MyThread::SyncTimeToThreads(some_time_struct t)
{
...
PostThreadMessage(TheTargetThread,TIME_SYNC_MSG,t,NULL);
PostThreadMessage(TheOtherTargetThread,TIME_SYNC_MSG,t,NULL);
...
}
ugly and not really a good solution, as u should have access to the variable in the context you discribed, so i would hunt around find out why you cant access it normally before considering other options.
|
|
|
|
|
Hi,
I initialized my var1=-1, then changed its value in one thread. I was able to access it in other thread without any problem.
Thank you for trying.
Niks
|
|
|
|
|
I found how to get the index of row in listview when you DoubleClick
this is the code
/////////////////////////////////////////////////////////////////////
String *field1;
int rowvar=1;
field1 = listView1->Items->Item[listView1->FocusedItem->get_Index()]->SubItems->Item[rowvar]->Text;
/////////////////////////////////////////////////////////////////////
This Works very fine, But i need to sort the values in the listview when i click on a column.
any one have idea how to sort by header???
|
|
|
|
|
wael_r wrote: any one have idea how to sort by header?
Look at this article[^]
I assume you will be able to translate the VB,C# sample code to CLI.
|
|
|
|
|
Hey,
When obtaining a key to decrypt a file encrypted using RC4 algorithm, CryptImportKey() fails.
The error says, "Invalid type specified".
What may be the possible reasons for this ?
It fails when I export the key in one application and import it in another application.
Has this something to do with storage of keyBLOB (I store it in a text file while exporting the key and read it from the text file while importing from a different application)?
Or is there some other reason that may lead it to failure.
Please reply at the earliest.....
Regards,
|
|
|
|
|
try to be more specific:
is it a build-time or a run-time problem.
what is the exact message
show some code, and indicate in exactly which line it fails
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Any idea why doesn't this compile?
#include "stdafx.h"
#include <bitset>
#include <iostream>
#include <ctime>
using namespace System;
int main(array<System::String ^> ^args)
{
const int N = 2000000;
clock_t cstart = clock();
bitset<N + 1> b;
int count = 0;
int i;
for (i = 2; i <= N; i++)
b.set(i);
i = 2;
while (i * i <= N)
{
if (b.test(i))
{
count++;
int k = 2 * i;
while (k <= N)
{
b.reset(k);
k += i;
}
}
i++;
}
while (i <= N)
{
if (b.test(i)) count++;
i++;
}
clock_t cend = clock();
double millis = 1000.0 * (cend - cstart) / CLOCKS_PER_SEC;
cout << count << " primes \n" << millis << " milliseconds\n";
return 0;
}
Errors:
Error 4 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 19 SieveOfErathostenes
Error 5 error C2228: left of '.set' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 19 SieveOfErathostenes
Error 6 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 24 SieveOfErathostenes
Error 7 error C2228: left of '.test' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 24 SieveOfErathostenes
Error 8 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 30 SieveOfErathostenes
Error 9 error C2228: left of '.reset' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 30 SieveOfErathostenes
Error 10 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 39 SieveOfErathostenes
Error 11 error C2228: left of '.test' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 39 SieveOfErathostenes
Error 12 error C2065: 'cout' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 46 SieveOfErathostenes
NOTE:
1. Core Java Vol I 8th Ed. Pg. 713 (727)
Jon
|
|
|
|
|
is this the right forum for you?
apart from your Java note, I see code that looks like regular C++, not managed C++/CLI which is the subject of this forum.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
|
jon_80 wrote: That's what I've been told ma'am
Luc is not a female name!
Best Wishes,
-David Delaune
|
|
|
|
|
His post did not help much anyway
Jon
|
|
|
|
|
In general I recommend you study and solve the first error message first, so when asking about some questions you should make sure to include the first error message or other symptom. That will make it easier on everyone.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
You forgot using namespace std;
|
|
|
|
|
Any idea why this code doesn't compile?
<pre>
// SieveOfErathostenes.cpp : main project file.
#include "stdafx.h"
#include <bitset>
#include <iostream>
#include <ctime>
using namespace System;
int main(array<System::String ^> ^args)
{
const int N = 2000000;
clock_t cstart = clock();
bitset<N + 1> b;
int count = 0;
int i;
for (i = 2; i <= N; i++)
b.set(i);
i = 2;
while (i * i <= N)
{
if (b.test(i))
{
count++;
int k = 2 * i;
while (k <= N)
{
b.reset(k);
k += i;
}
}
i++;
}
while (i <= N)
{
if (b.test(i)) count++;
i++;
}
clock_t cend = clock();
double millis = 1000.0 * (cend - cstart) / CLOCKS_PER_SEC;
cout << count << " primes \n" << millis << " milliseconds\n";
return 0;
}
</pre>
Errors:
Error 4 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 19 SieveOfErathostenes
Error 5 error C2228: left of '.set' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 19 SieveOfErathostenes
Error 6 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 24 SieveOfErathostenes
Error 7 error C2228: left of '.test' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 24 SieveOfErathostenes
Error 8 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 30 SieveOfErathostenes
Error 9 error C2228: left of '.reset' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 30 SieveOfErathostenes
Error 10 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 39 SieveOfErathostenes
Error 11 error C2228: left of '.test' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 39 SieveOfErathostenes
Error 12 error C2065: 'cout' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 46 SieveOfErathostenes
NOTE:
1. Core Java Vol I 8th Ed. Pg. 713 (727)
Jon
|
|
|
|
|
You forgot a using namespace std; You need this for iostream and bitset .
Dybs
|
|
|
|
|
Any know how to resize a column in datagrid
This is my code:
/////////////////////////////////////////////
dad = new OdbcDataAdapter("select * from MesgDetails", cn);
ds->Clear();
dad->Fill(ds);
dataGrid1->PreferredColumnWidth = 82;
dataGrid1->DataSource = ds->Tables->Item[0];
//////////////////////////////////////////////
i want to resize a specific column.
|
|
|
|
|
Hi,
I am kind of new to CLI, and I am unsure how to run an application on a remote PC from a local PC. I am looking for a way to do this via command line on windows. The idea is:
I need something similar to the services control 'sc'. But instead of controlling services remotely, I would like to run files on a PC in the network. I have found some custom applications to do this, but I would rather write my own batch scripts. Surely if they can write apps to do it, then there must be some way.
I think taskkill has a parameter to specify a machine to remotely end a process, but I need to start one!
I have tried:
- Map the remote drive to my local PC and then access the files, but of course it will run on my LOCAL PC, not the other PC
- Googling a lot, failing a lot, finding too many 3rd party apps, finding too many C# code snippets
Does anyone know a CLI command that can do this? Just the command or an idea would do, I just need a better starting point.
Some insight would be really appreciated. Thanks
|
|
|
|
|
See_Sharp wrote: Does anyone know a CLI command that can do this? Just the command or an idea would do, I just need a better starting point.
There is no simple CLI 'command' to execute code on remote computers. If it were that simple to execute code on remote machines we would be in big trouble. Mark Russinovich over at Microsoft created a great tool called PsExec [^]which does exactly what your describing. You can even use it in batch files.
It is certainly possible to create a tool which does the same thing. Mark described how psexec is implemented in this WindowsITPro article[^] but unfortunately it requires a subscription to be read. If you look around the net you will find others who have discussed how PsExec works:
PsExec Internals[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Thank you David, I'll definately look into it
I was hoping that something built-in from Windows existed for this, like 'sc', but I guess it can't always be that easy!
|
|
|
|
|
Hi again,
I tried many things now, but nothing worked.
The question isn't really difficult. I have a Status_line label which is
actualised circa 20 times a seconde. In that label is always the actual running
number written. But I do not get rid of that horrible flickering!
I tried already to doublebuffer, but it seems to work only on Graphics.
The writing function has to take the textcolor, backcolor and string as parameter,
so I cannot statically DrawString on the label graphics.
Isn't there a way to prevent that flickering?
Thanks! cherry
|
|
|
|
|
Hi,
1.
AFAIK all Controls can be double-buffered, and that is the best way to improve the situation
2.
some improvement can be achieved by NOT updating the control when all the parameters remain the same,
i.e. compare the current ForeColor, BackColor and Text, with the new ones, and only update when there is a difference.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|