Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
arienchen Absent Member.
Absent Member.
2800 views

usleep block other thread

Dears,

I have a COBOL program which would perform threads and call C function defined in direct.c 

and the C function would call usleep() internally.

As my understanding, C usleep() would suspend current thread only.

But I found the C function would block other thread in COBOL, ie 'perform thread'

So, I write a simple C function just call usleep() and relink runtime.

The behavior is the same as I expect.

COBOL call C usleep() would block other COBOL thread.

If I replace the C fuction to C$SLEEP, the COBOL threads would run normally.

My environment is AcuGT v9, AIX 7 64 bit

Thanks & Regards,

ARIEN

0 Likes
4 Replies
arienchen Absent Member.
Absent Member.

RE: usleep block other thread

I have review the document for C$SOCKET.  documentation.microfocus.com/.../BKPPPPLIBRS089.html

It mention:  

Note: If a COBOL thread calls one of these operations, all threads are blocked until the operation is finished and control is returned to the COBOL program.

I am wondering whether the COBOL thread is native implementation under OS(for example: Unix pthread)

Otherwise, why C$SOCKET would block other threads.

The behavior is same as I call C usleep.

0 Likes
Bruce_Sinclair Absent Member.
Absent Member.

RE: usleep block other thread

extend COBOL does not use OS facilitities for threading, but instead uses a runtime implementation of threading.  That is, the runtime switches between the various threads defined in an extend COBOL program.  Here's some information from the ACUCOBOL-GT User's Guide:

6.8.7 Multithreading and Multiprocessor Systems

ACUCOBOL-GT implements multithreading in a machine-independent fashion. It neither needs nor uses any multithreading capabilities of the host system. This has several advantages:

   You can run multithreaded programs in environments that do not otherwise support multithreading.

   Multithreaded programs run the same way under different environments.

   ACUCOBOL-GT can provide features not universally available in multithreaded systems, such as the link between windows and threads.

There are, however, a few disadvantages to this implementation. Chief among these is that the operating system is not aware that there are multiple threads running in the runtime's process. This is primarily an issue on systems that have multiple processors. Some of these systems can allocate additional processors to a task if they know that the task contains more than one thread--up to one processor per thread. But because these systems do not see the runtime as a multithreaded entity, multiprocessor allocation does not happen.

Typically, multiprocessor systems are used to provide support for more users. By having more processors in the system, the system can run more processes at once, and in this way increase the number of users the machine can effectively support. But the system will not increase performance for a single process (assuming that the process gets 100% of the CPU's time--an unrealistic assumption in a production environment). In practice, a multiprocessor machine will usually not benchmark any better than a single processor machine for single-task benchmarks, but they will provide much better total throughput in a multi-user production environment.

In summary, multithreading an ACUCOBOL-GT program will not affect its performance in any special way on a multiprocessor machine. Any gain, or loss, will be the same as for a single processor system.

0 Likes
arienchen Absent Member.
Absent Member.

RE: usleep block other thread

Thanks for the prompt attention.

In other words,

When COBOL call C function which run for a long time,

the COBOL THREAD would be suspended.

Because COBOL runtime is single process/thread in OS  level.

If the C function is a long-running process,

the better practice :

Make the C function to create its own thread for its own process

and return to COBOL ASAP.

0 Likes
Bruce_Sinclair Absent Member.
Absent Member.

RE: usleep block other thread

That is correct.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.