Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8501655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:16:14+00:00 2026-06-11T01:16:14+00:00

I have a very simple thread loop public void ClientLoop(object AContext) { var context

  • 0

I have a very simple thread loop

public void ClientLoop(object AContext)
{
    var context = (ZMQ.Context) AContext;

    Socket client = CreateServerSocket(context);

    while (true)
    {
        try
        {
            Context.Poller(requestTimeout*1000, client);
        }
        catch (Exception e)
        {
            if (e.Errno == ETERM)
            {
                //Catch a termination error. 
                Debug.WriteLine("Terminated! 1");
                return;
            }
        }
    }
}

And a dispose that looks like the following

public void Dispose()
{
    _context.Dispose();
}

The client socket is created with linger set to zero and a poller in handler set. The socket is also a request socket.

Once the dispose is called the poller excepts and falls into the try except block. However after the dispose doesn’t continue like I thought it would. This is how the ZGuide says to handle destruction of the context and sockets however it doesn’t seem to be working in this case.

What have I missed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:16:15+00:00Added an answer on June 11, 2026 at 1:16 am

    However after the dispose doesn’t continue like I thought it would.

    You mean the call to Dispose hangs/blocks? That is because you did not close the client socket before you return from the thread. (My syntax below may be wrong but you get the idea)

            if (e.Errno == ETERM)
            {
                //Catch a termination error. 
                Debug.WriteLine("Terminated! 1");
                client.Close();
                return;
            }
    

    Setting linger to 0 is not enough – that just prevents the socket closure from blocking. You must still close the socket in your worker thread to prevent the _context.Dispose() from blocking.

    This is how the ZGuide says to handle destruction of the context and sockets…

    Well – that’s true but there is an important qualifier in the document:

    We’ll get to multithreading in the next chapter, but because some of you will, despite warnings, will try to run before you can safely walk, below is the quick and dirty guide to making a clean exit in a multithreaded ØMQ application.

    Later in the document they describe how to do a clean shutdown by having a dedicated socket in each thread which listens to a kill signal. Consider enhancing your worker thread by doing something similar. This way you can request each thread to shut itself down by sending each thread a message – each thread then exits its run loop, does a clean close on it’s socket(s) and exits. Once all threads have exited you can safely dispose of the context without having any errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a thread that is very simple. The only thing the Thread object
I have created a GUI for starting a Thread which does something very simple.
I have a very simple extension method that looks like this: public static string
I am writing an app that’s a very simple web service client. I have
Let's say we have very simple Java class MyClass . public class MyClass {
I have very simple piece of code. The goal is when i input four-digit
I have very simple OpenGL ES example similar to Hehe's example : http://nehe.gamedev.net/tutorial/ios_lesson_02__first_triangle/50001/ As
I have very simple window where I have 2 buttons - one for cancel,
I have a very simple table called Member , which consists of the following:
I have a very simple fxml file, with a checkbox: ... <AnchorPane id=AnchorPane xmlns:fx=http://javafx.com/fxml

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.