Re: creating a thread in c++ in unix (must it be POSIX?)

From: john (qwejohn_at_hotmail.com)
Date: 04/28/03


Date: 27 Apr 2003 22:35:10 -0700

Hello,
Thanxs for all the answers in response to my post.
As I understand , all pf you talk about POSIX threads.
Is the only possibility of using thread in UNIX is
by POSIX threads?

I saw , for example, in this newsgroup the following example:
(http://groups.google.com/groups?q=threads+group:comp.unix.programmer&hl=en&lr=&ie=UTF-8&oe=UTF-8&group=comp.unix.programmer&selm=1012544105.263965%40sj-nntpcache-3&rnum=2)

Does it use the POSIX threads?

************* Code ***************
#include <thread.h>
#include <signal.h>

void default_signal_handler(int signal) {
  printf("tid = %d in signal handler\n", thr_self());
}

void func(void) {
  printf("thread tid = %d created\n", thr_self());
  signal(SIGURG, default_signal_handler);
  select(0, NULL, NULL, NULL, 0);
  while(1);
}

int main() {
  unsigned int tid1, tid2;
  int ret;

  thr_create(NULL, NULL, (void *)func, NULL, THR_DETACHED, &tid1);
  thr_create(NULL, NULL, (void *)func, NULL, THR_DETACHED, &tid2);

  sleep(1);

  thr_kill(tid1, SIGURG);
  thr_kill(tid2, SIGURG);

  while (1);
}

regards
john

Alex Pavloff <BLAHapavloff@BLAHeason.com> wrote in message news:<me8oavsgkgsko83en767fou8m7sbadmhti@4ax.com>...
> On 27 Apr 2003 03:09:55 -0700, qwejohn@hotmail.com (john) wrote:
>
> >Hello,
> >what is the recommended way of creating a thread in C++
> >in unix?
> >
> >(the parallel of createThread in windows , which creates
> >a thread which , when starts to run , reaches a specified
> >method (which is specified in the createThread call)?
> >regards
> >john
>
> Take a look at the CommonC++ libraries. They provide classes that
> wrap the POSIX api.
>
> http://www.gnu.org/software/commonc++/



Relevant Pages

  • POSIX thread programming
    ... I have a few questions about POSIX threads programming regarding ... I tested the code on a machine running ... int *i; ... int flag; ...
    (comp.programming.threads)
  • SUMMARY: void main(int argc, char *argv[]) question
    ... The consensus is that the use of void on main is wrong (The book ... return and int. ... >In trying to compile some old test Unix C programs... ... Why do those old UNIX programs used void ... ...
    (SunManagers)
  • Re: fork() & exec1 problem
    ... I get an error message returned by the switch/case ... > int TryLock; ... > void UnLock; ... advice that can help you with all UNIX programs you write -- not just this ...
    (comp.unix.programmer)
  • Re: c++ comp. argument passing and prefix operator
    ... ran the code using C++ compileralso in Unix env.In fact the on Unix i got the correct. ... is a sequence point after the declaration/definition/initialisation of 'a' ... using namespace std; void fn(int, ...
    (microsoft.public.vc.language)
  • Re: threads in C++ class ?
    ... When I see examples using posix threads they mainly have a ... I just want to let secondary thread do its job and not ... I was also looking at boost threads, ... void start ...
    (comp.programming.threads)