|
Quote: The only thing you wouldn't have is the path of the threads that are depending on another - that's the kind of dependency I try to avoid altogether.
If I want to test a synchronization primitive - here a Reader Writer lock, how can you avoid thread dependencies? It is all about the behavior on different threads, because that is what synchronization primitives do. Imagine a unit test (in pseudocode) that can perform the same test from scratch. How this may look like?
Quote: Thomas Maierhofer (Tom) wrote:
Our old approach of concurrency testing does not fit in very well: I don't see the difference; either you .And(bla) or Assert(bla). As soon as it is repeated on each line, it becomes noise during reading.
Maybe so you're just writing unit tests or maybe you are doing a little TDD. BDD is a slightly different approach. Love it or hate it.
In fact the ConcurrencyTester should work well in TDD and BDD scenarios.
|
|
|
|
|
Thomas Maierhofer (Tom) wrote: If I want to test a synchronization primitive - here a Reader Writer lock, how
can you avoid thread dependencies? There's no silver bullet there, no single solution that will work in all cases. Instead of waiting for the reader-thread you might want to look at a queue.
Thomas Maierhofer (Tom) wrote: Imagine a unit test (in pseudocode) that can perform the same test from scratch. It would be testing whether the story as written works under the current conditions. How does it work if there's a deadlock because no reader-thread can be started (say, because someone is writing to the locked file)?
Thomas Maierhofer (Tom) wrote: BDD is a slightly different approach. Love it or hate it. I can't do either until I know it a bit better.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Quote:
Thomas Maierhofer (Tom) wrote:
If I want to test a synchronization primitive - here a Reader Writer lock, how
can you avoid thread dependencies?There's no silver bullet there, no single solution that will work in all cases. Instead of waiting for the reader-thread you might want to look at a queue.
Sorry you totally misunderstood me. If you are DEVELOPING a Reader Writer Lock Class, how could you possibly test YOR OWN Reader Writer Lock Class without threads? There is no queue, YOU are developing a Reader Writer Lock Class.
|
|
|
|
|
Thomas Maierhofer (Tom) wrote: Sorry you totally misunderstood me. If you are DEVELOPING a Reader Writer Lock
Class I did not misunderstand; I would not have them in a single class.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
Thomas Maierhofer (Tom) wrote: Assuming I am the guy who developed this class, how would I test this class? Thouroughly, I hope.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello guys. How do I send my slave application (in windows forms) multiple commands ? I am trying to show frame rate and video bitrate using two commands in mplayer (running as a slave app in windows form). Bit it shows only one things at a time, alternately. Here is what I am trying
objPlayerProcess.StandardInput.WriteLine("osd_show_property_text ${fps}" + "(FrameRate)");
objPlayerProcess.StandardInput.WriteLine(objPlayerProcess.StandardInput.NewLine);
objPlayerProcess.StandardInput.WriteLine("osd_show_property_text ${video_bitrate}" + "(BitRate)");
How do I show both of them, at the same time ? Thanks for any input.
|
|
|
|
|
There's nothing wrong with the code you're showing here other than I can't see how ${fps} and ${video_bitrate} should be replaced by some value. The actual problem is probably located in your receiving code or display code.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Sascha Lefévre wrote: .... other than I can't see how ${fps} and ${video_bitrate} should be replaced by some value.
Yes. Those will be handled by the player internally. Again, values are being shown but...one by one. Not at the same time.
|
|
|
|
|
With the second sentence of my previous reply I tried to hint at you that you need to provide more information / code
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
The slave application will be receiving them one by one. If you want to send them together, then make a single line of it, or change the slave to accept multiple arguments and wait with processing until there's a "I'm done sending stuff" command.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I tried to send them in single line like this ...
objPlayerProcess.StandardInput.WriteLine("osd_show_property_text ${fps}" + "(FrameRate)" + objPlayerProcess.StandardInput.NewLine + "osd_show_property_text ${video_bitrate}" + "(BitRate)");
I don't know if there exists another method. This did not work either. It shows them alternately.
|
|
|
|
|
..because it is not a single line; there's a newline in there.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
nope. it did not work either. i am kinda stuck.
|
|
|
|
|
Post the code where your player is reading these values and we'll have a look
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
Iam Know how send and received but problem how know the state connected with IP , Port
this my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
namespace etherent_send_and_recive_data
{
public partial class Form1 : Form
{
UdpClient udpClient;
private IPEndPoint ipend;
public Form1()
{
InitializeComponent();
udpClient = new UdpClient();
}
private void send_data_through_etherent( string send_data_ETH)
{
byte[] senddataETH = ASCIIEncoding.ASCII.GetBytes(send_data_ETH);
udpClient.Send(senddataETH,4);
}
private void button1_Click(object sender, EventArgs e)
{
int port;
byte res;
button1.Text = "disconnected";
port = int.Parse(textBox2.Text);
ipend = new IPEndPoint(IPAddress.Parse(textBox1.Text), port);
try
{
udpClient.Connect(ipend);
}
finally
{
button1.Text = "connected";
}
}
private void switch1_StateChanged(object sender, NationalInstruments.UI.ActionEventArgs e)
{
if(switch1.Value==true)send_data_through_etherent("S11E");
else send_data_through_etherent("S10E");
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if(textBox2.Text != string.Empty)
{
if (textBox1.TextLength >= 11) button1.Enabled = true;
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
if (textBox2.Text != string.Empty)
{
if (textBox1.TextLength >= 11) button1.Enabled = true;
}
}
}
}
the problem now in code button1_Click I need know the real state for connected for example if connected the button.text="connected" if closed or not connected button.text="disconnected"
how code for udp client about connected and closed
Regards
|
|
|
|
|
Ummm...UDP is connectionLESS so your question makes no sense.
|
|
|
|
|
Hi,
thank you for my support
Sir my equation how know the state for connection
i mean if press button will connected with ip for example 192.168.1.1 and port for example 10001 her equation how can know the connected with this ip and port is Successfully
now my project when press button is write connected but not iam sure the system is connected with this ip and port
I try to search about how know the state for connection with ip
some time is connected is ok but if closed socket must be program say for me now is disconnected
I hope now clear my equation
Best Regards
|
|
|
|
|
Your using UDP. Again, it's a CONNECTIONLESS protocol. THERE IS NO CONNECTION!
It's like tuning in a radio. The radio station doesn't have a connection to your radio and doesn't guarantee that you can receive the signal.
|
|
|
|
|
Thank Sir Now clear information about UDP
I try using TCP in the same project
Regards
|
|
|
|
|
TCP is like a phone call, UDP is like putting messages in a bottle and tossing them into the sea. If you need persistent connections and reliable communications you need to use TCP. If you do use UDP you have to appreciate that you just get data as it comes in, there is no connection or reliability in the data you receive. UDP is only suitable for a limited number of applications, or maybe if you're on a local LAN with an old-school token-ring network.
|
|
|
|
|
thank sir for this information and thank you for my support
now Iam understand about UDP
please Sir can be modification for my code by use TCP
or can be put small example about connected IP and Recived data and send data by used TCP
Best regards
|
|
|
|
|
Hi,
This code from my friend about how can check the connection
if connected or not also continuous check
public bool TestConnection(string ip)
{
Ping p = new Ping();
try
{
PingReply reply = p.Send(ip, 3000);
if (reply.Status == IPStatus.Success)
return true;
}
catch (Exception e)
{
return false;
}
return false;
for example
private void button2_Click(object sender, EventArgs e)
{
busy = true;
if (TestConnection(textBox2.Text))
{
Byte[] sendBytes = Encoding.ASCII.GetBytes("B");
udpClient.Send(sendBytes, sendBytes.Length);
var receivedData = udpClient.Receive(ref ep);
textBox1.Text = Encoding.ASCII.GetString(receivedData);
label1.Text = Encoding.ASCII.GetString(receivedData);
}
busy = false;
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
if (!busy)
{
Byte[] sendBytes = Encoding.ASCII.GetBytes("C");
udpClient.Send(sendBytes, sendBytes.Length);
var receivedData = udpClient.Receive(ref ep);
textBox1.Text = Encoding.ASCII.GetString(receivedData);
}
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Thread.Sleep(500);
if (TestConnection(textBox2.Text))
{
backgroundWorker1.RunWorkerAsync();
}
else
{
MessageBox.Show("No Device Connected");
}
}
|
|
|
|
|
Hello all, I have a quick question. I have a service running that continually checks the database for a record, if a record exist then it process the record and deletes it. The service starts a thread that runs a while look until it tells it to stop. Is it better to create the connection inside or outside of the loop? Keep in mind that this loop could run for days. See below for the two options:
while (!stopEvent.WaitOne(0, false))
{
using (SqlConnection dbConnection = new SqlConnection(connectionString))
{
dbConnection.Open();
using (SqlCommand dbCommand = new SqlCommand("SELECT * FROM [TableName]", dbConnection))
{
using (SqlDataReader dbReader = dbCommand.ExecuteReader())
{
if (dbReader.Read())
{
}
}
}
}
System.Threading.Thread.Sleep(100);
}
using (SqlConnection dbConnection = new SqlConnection(connectionString))
{
dbConnection.Open();
while (!stopEvent.WaitOne(0, false))
{
using (SqlCommand dbCommand = new SqlCommand("SELECT * FROM [TableName]", dbConnection))
{
using (SqlDataReader dbReader = dbCommand.ExecuteReader())
{
if (dbReader.Read())
{
}
}
}
}
System.Threading.Thread.Sleep(100);
}
|
|
|
|
|
I'd go for option 1 - create and dispose of the connection within the loop. You don't want to hold a connection open when you're not using it, and the Thread.Sleep call isn't using it.
I'd also suggest adding a TOP 1 to your query, since you're only expecting to read and process a single record. Either that, or change the if (dbReader.Read()) { ... } to while (dbReader.Read()) { ... } to read and process all of the returned rows.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|