재진입 코드 생성 및 호출하기
단일 스레드 또는 멀티스레드 환경에 대한 재진입 코드 생성 및 호출
기본적으로, 생성 코드는 크기가 구성 객체 설정 StackUsageMax
에 저장된 최대 스택 사용 값을 초과하는 변수에 대해 static
변수를 생성합니다. static
변수의 데이터는 함수 호출 간에 유지됩니다. 마찬가지로 MATLAB® 전역 변수 및 영속 변수의 데이터는 함수 호출 간에 사라지지 않고 계속 존재합니다. 따라서 메인 함수가 생성 코드를 여러 스레드에서 실행하는 경우 불확실한 경쟁 상태가 발생할 수 있습니다.
여러 스레드에서의 동시 실행에 더 적합한 코드를 생성하려는 경우에는 MultiInstanceCode
구성 옵션을 사용할 수 있습니다. 이 옵션을 사용하면 생성 코드가 로컬의 스레드 저장 공간을 초과할 수 있는 데이터를 구조체 정의 안에 래핑하므로 해당 구조체에 대해 스레드 안전(thread-safe)이 보장되는 메모리를 개별적으로 할당할 수 있습니다. 마찬가지로 코드 생성기는 영속 데이터 및 전역 데이터를 자체 메모리 구조체 안에 래핑합니다. 이 메모리를 공유해서는 안 되는 경우에는 스레드에서 사용하는 데이터 구조체에 개별 메모리를 할당할 수 있습니다.
도움말 항목
재진입 코드 기본 사항
- Reentrant Code
Reentrant code is a reusable programming routine that multiple programs can use simultaneously. - API for Generated Reusable Code
Use generated reusable code. - Specify Generation of Reentrant Code
Generate reentrant code in the MATLAB Coder™ app or at the command line. - Call Reentrant Code in a Single-Threaded Environment
Use generated reentrant code in a single-threaded environment. - Call Reentrant Code in a Multithreaded Environment
Use generated reentrant code in a multithreaded environment.
워크플로
- Generate Reentrant C Code from MATLAB Code
Generate reusable, reentrant C code. - Call Reentrant Code with No Persistent or Global Data (UNIX Only)
Generate reentrant code that uses POSIX thread (pthread) libraries. - Call Reentrant Code — Multithreaded with Persistent Data (Windows Only)
Generate reentrant code that uses libraries that are specific to Windows® platforms. - Call Reentrant Code — Multithreaded with Persistent Data (UNIX Only)
Generate reentrant code that uses POSIX thread (pthread) libraries.