Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Trouble with threads  (Read 4214 times)

0 Members and 1 Guest are viewing this topic.

strongdrink

  • Newbie
  • *
  • Posts: 43
    • View Profile
    • Email
Trouble with threads
« on: March 21, 2011, 09:38:50 pm »
HAI!

I am creating a file manager for Linux. I need to run iNotify while my app is running..
When it runs, it either runs my app, or inotify. but it cant run both. here is my code...

Code: [Select]


...

void inotify_check (void*) {

  ...

}

...

int main () {

  ...

  sf::Thread Thread(&inotify_check);

  while (running) {

    ...

    Thread.Launch();

    ...

  }

  ...

}


When I do this.. the thread runs, but it won't proccess the main part of the app.

I also tried this...

Code: [Select]


...

void inotify_check (void*) {

  ...

}

...

int main () {

  ...

  sf::Thread Thread(&inotify_check);

  while (running) {

    ...

    Thread.Launch();

    ...

    Thread.Terminate();

  }

  ...

}


But this keeps returning the error "Failed to create thread"

KTHXBYE!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Trouble with threads
« Reply #1 on: March 21, 2011, 10:22:40 pm »
We need to see more code. What would be great is a minimal and complete example that reproduces the problem.
Laurent Gomila - SFML developer

strongdrink

  • Newbie
  • *
  • Posts: 43
    • View Profile
    • Email
Trouble with threads
« Reply #2 on: March 24, 2011, 02:10:33 pm »
Ok i got one thing working.. it runs the thread.. but it only runs it once.

e.g.

Code: [Select]

#include <SFML/System.hpp>
#include <iostream>
using namespace std;

bool running = true;

void MyThreadFunc(void* UserData) {

  cout << "hai";

}

int main () {

  sf::Thread Thread1(&MyThreadFunc);
  Thread1.Launch();

  while (running) {

    cout << "Welcome!";

  }

}


EDIT:

I got this working... but I am trying to do this with iNotify THEN it jams... should i post my code?

EDIT 2:

iNotify has to be constantly running and looking for events while my app is running

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Trouble with threads
« Reply #3 on: March 24, 2011, 02:22:16 pm »
Quote
I got this working... but I am trying to do this with iNotify THEN it jams... should i post my code?

Yes please.
Laurent Gomila - SFML developer

strongdrink

  • Newbie
  • *
  • Posts: 43
    • View Profile
    • Email
Trouble with threads
« Reply #4 on: March 24, 2011, 02:25:37 pm »
It's several hundred lines of code... I'll just try to explain what I need to do

I need to run my program, but while my program is running, I need to run iNotify constantly (checks system events)

strongdrink

  • Newbie
  • *
  • Posts: 43
    • View Profile
    • Email
Trouble with threads
« Reply #5 on: March 24, 2011, 02:39:33 pm »
got it :D