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

  • SEARCH
  • Home
  • 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 7960789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:51:22+00:00 2026-06-04T04:51:22+00:00

I have two classes evaluated threads but I cannot send a signal from one

  • 0

I have two classes evaluated threads but I cannot send a signal from one to another, Some ideas why it doesn’t work:

class 1:

#include "timer.h"
#include <ncurses.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include "mutexy.h"

Timer::Timer() {
}

Timer::~Timer() {
}

void Timer::startThread() {
    pthread_create(&thread, NULL, runInstance, reinterpret_cast<void *>(this));
}

void Timer::joinThread() {
    pthread_join(thread, NULL);
}

void Timer::init() {
    this->hh = 0;
    this->day = 1;
    this->month = 1;
    this->year = 2011;
}

void Timer::run() {
    while(true) 
    {
        if(hh==24) {
            hh = 0;
            day++;
            if(day==31) {
                day=1;
                month++;
                if(month==13) {
                    year++;
                    month==1;
                }
            }
        }
        for (int i=0; i<10; i++) {
            if(hh==7) {
                hh=20;
                pthread_cond_signal(&brak_biletow_treshold);
            }
        }

        sleep(1);
        hh++;
        pthread_yield();
    }
}

void* Timer::runInstance(void *instance) {
    Timer *d = reinterpret_cast<Timer *>(instance);

    d->run();

    return NULL;
}

class2:

#include "flight_list.h"
#include <ncurses.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include "mutexy.h"

string cities[8] = {"Warszawa","Berlin","Paryz","Londyn","Dublin","Madryt","Wieden","Moskwa"};


FlightList::FlightList() {
    srand(time(NULL));
}

FlightList::~FlightList() {
}

void FlightList::startThread() {
    pthread_create(&thread, NULL, runInstance, reinterpret_cast<void *>(this));
}

void FlightList::joinThread() {
    pthread_join(thread, NULL);
}

void FlightList::init() {
    flightTab = new Flight *[10];
    for (int i=0; i<10; i++) {
        int city = rand()%7+1;
        flightTab[i] = new Flight(i*2+2,i+2,1,2011,60,cities[0],cities[city]); 
    }
}

void FlightList::run() {
    while(true) 
    {
        pthread_mutex_lock(&bilety_mutex);
        pthread_cond_wait(&brak_biletow_treshold, &bilety_mutex);
        for (int i=0; i<10; i++) {
                for(int i=0; i<9; i++)
                    flightTab[i] = flightTab[i+1];
                int city = rand()%7+1;
                flightTab[9] = new Flight(4,10,2,2011,60,cities[0],cities[city]); 

        }
        pthread_mutex_unlock(&bilety_mutex);
        pthread_yield();
    }
}

void* FlightList::runInstance(void *instance) {
    FlightList *d = reinterpret_cast<FlightList *>(instance);

    d->run();

    return NULL;
}

and header file with mutex and cond_t:

#include <pthread.h>

static pthread_mutex_t bilety_mutex;
static pthread_mutex_t loty_mutex;
static pthread_cond_t brak_biletow_treshold = PTHREAD_COND_INITIALIZER

;

mutex are working but signal is not recived by thread :S

  • 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-04T04:51:24+00:00Added an answer on June 4, 2026 at 4:51 am

    Each translation unit will have it’s own brak_biletow_treshold instance because you’ve declared them static (which effectively restricts the scope to the current translation unit).

    You need to change the way your “globals” are declared and accessed. I suggest that you pass the the condition to the constructor of the two classes.

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

Sidebar

Related Questions

I have two classes one of which inherits from the other. Im trying to
I have two classes, Person and Company, derived from another class Contact. They are
I have two classes with a ManyToMany relationship. I'd like to select one from
I have two classes, one for articles and another for the cart. The cart
I have two classes. One(Person) for getters and setters, and another(People) for compute the
I have two classes generated by LINQ2SQL both from the same table so they
I have two classes that refer to each other, but obviously the compiler complains.
I have two classes, one nested in the other. Public Class Operation Public Property
I have two classes(Book,Software) that inherit from the Product class. these two classes have
I have two classes, a server and some clients. The server class make a

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.