9.5 Limits on Blocking Operations in main

CONVERSE has a rule about blocking operations -- there are certain pieces of code that may not block. This was an efficiency decision. In particular, the main function, CONVERSE handlers, and the CONVERSE startup function (see ConverseInit) may not block. You must be aware of this when using the POSIX threads functions with CONVERSE.

There is a contradition here -- the POSIX standard requires that the pthreads functions work from inside main. However, many of them block, and CONVERSE forbids blocking inside main. This contradition can be resolved by renaming your posix-compliant main to something else: for example, mymain. Then, through the normal CONVERSE startup procedure, create a POSIX thread to run mymain. We provide a convenience function to do this, called Cpthreads_start_main. The startup code will be much like this:

void mystartup(int argc, char **argv)
{
  CpthreadModuleInit();
  Cpthreads_start_main(mymain, argc, argv);
}

int main(int argc, char **argv)
{
  ConverseInit(mystartup, argc, argv, 0, 0);
}

This creates the first POSIX thread on each processor, which runs the function mymain. The mymain function is executing in a POSIX thread, and it may use any pthread function it wishes.

June 29, 2008
Charm Homepage