ChezZ
ChezZ
CC#
Created by ChezZ on 8/9/2024 in #help
attach console to a non console application?
Anyone know how to do this?
9 replies
CC#
Created by ChezZ on 8/4/2024 in #help
Generate a unique number given two other numbers between -10 and 10
Is this possible? I cannot seem to figure out an equation that doesn't have collisions.
10 replies
CC#
Created by ChezZ on 8/1/2024 in #help
Question regarding thread safety
Is it safe to call code on the foo object from multiple threads in this scenario? Like what happens if two threads try to access the foo object to call DoSomething() on instanceA at the same time?
static void Main()
{
var foo = new Foo();
foo.instanceA = new Bar();
foo.instanceB = new Bar();

//Assuming every method on Bar is thread safe is it safe to access the foo object to call a method on Bar from any thread?
foo.instanceA.DoSomething();


}
public class Foo
{
public Bar instanceA;
public Bar instanceB;
}

public class Bar
{
public void DoSomething()
{

}
}
static void Main()
{
var foo = new Foo();
foo.instanceA = new Bar();
foo.instanceB = new Bar();

//Assuming every method on Bar is thread safe is it safe to access the foo object to call a method on Bar from any thread?
foo.instanceA.DoSomething();


}
public class Foo
{
public Bar instanceA;
public Bar instanceB;
}

public class Bar
{
public void DoSomething()
{

}
}
10 replies
CC#
Created by ChezZ on 8/1/2024 in #help
Creating a thread that lives for as long as the application.
I wrote a server using a c library, I created two threads using
new Thread
new Thread
and have an infinite loop running in the threads method. One thread handles all socket related code, and adds incoming packets to be deserialized to a single producer single consumer queue. The other thread deserializes the packets. The codes works but it has a flaw. Creating the thread via
new Thread
new Thread
fails and I get an exception if the system running the app has no more threads available. is it possible to tell the app use an existing thread if creating a new one fails:
thread = new Thread(DoWork); //this line of code throws the exception if the cpu runs out of threads
thread.IsBackground = true;
shouldRun = true;

private void DoWork()
{

Init();
while (shouldRun == true)
{
Consume();
Tick();

}
}
thread = new Thread(DoWork); //this line of code throws the exception if the cpu runs out of threads
thread.IsBackground = true;
shouldRun = true;

private void DoWork()
{

Init();
while (shouldRun == true)
{
Consume();
Tick();

}
}
18 replies